mirror of
https://github.com/getgrav/grav.git
synced 2026-03-05 03:51:50 +01:00
load system blueprints as a fallback for pages
This commit is contained in:
@@ -13,27 +13,24 @@ class Types implements \ArrayAccess, \Iterator, \Countable
|
||||
use ArrayAccess, Constructor, Iterator, Countable, Export;
|
||||
|
||||
protected $items;
|
||||
protected $systemBlueprints;
|
||||
|
||||
public function register($type, $blueprint = null)
|
||||
{
|
||||
if (!$blueprint && $this->systemBlueprints && isset($this->systemBlueprints[$type])) {
|
||||
$useBlueprint = $this->systemBlueprints[$type];
|
||||
} else {
|
||||
$useBlueprint = $blueprint;
|
||||
}
|
||||
|
||||
if ($blueprint || empty($this->items[$type])) {
|
||||
$this->items[$type] = $blueprint;
|
||||
$this->items[$type] = $useBlueprint;
|
||||
}
|
||||
}
|
||||
|
||||
public function scanBlueprints($path)
|
||||
{
|
||||
$options = [
|
||||
'compare' => 'Filename',
|
||||
'pattern' => '|\.yaml$|',
|
||||
'filters' => [
|
||||
'key' => '|\.yaml$|'
|
||||
],
|
||||
'key' => 'SubPathName',
|
||||
'value' => 'PathName',
|
||||
];
|
||||
|
||||
$this->items = Folder::all($path, $options) + $this->items;
|
||||
$this->items = $this->findBlueprints($path) + $this->items;
|
||||
}
|
||||
|
||||
public function scanTemplates($path)
|
||||
@@ -48,6 +45,10 @@ class Types implements \ArrayAccess, \Iterator, \Countable
|
||||
'recursive' => false
|
||||
];
|
||||
|
||||
if (!$this->systemBlueprints) {
|
||||
$this->systemBlueprints = $this->findBlueprints('blueprints://pages');
|
||||
}
|
||||
|
||||
foreach (Folder::all($path, $options) as $type) {
|
||||
$this->register($type);
|
||||
}
|
||||
@@ -83,4 +84,19 @@ class Types implements \ArrayAccess, \Iterator, \Countable
|
||||
ksort($list);
|
||||
return $list;
|
||||
}
|
||||
|
||||
private function findBlueprints($path)
|
||||
{
|
||||
$options = [
|
||||
'compare' => 'Filename',
|
||||
'pattern' => '|\.yaml$|',
|
||||
'filters' => [
|
||||
'key' => '|\.yaml$|'
|
||||
],
|
||||
'key' => 'SubPathName',
|
||||
'value' => 'PathName',
|
||||
];
|
||||
|
||||
return Folder::all($path, $options);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user