load system blueprints as a fallback for pages

This commit is contained in:
Gert
2015-05-20 20:33:40 +02:00
parent e4b65d5d7f
commit e6d58b780e

View File

@@ -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);
}
}