From e6d58b780e85d0a4b2fc2f7e024c8ff3e76fc205 Mon Sep 17 00:00:00 2001 From: Gert Date: Wed, 20 May 2015 20:33:40 +0200 Subject: [PATCH] load system blueprints as a fallback for pages --- system/src/Grav/Common/Page/Types.php | 40 +++++++++++++++++++-------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/system/src/Grav/Common/Page/Types.php b/system/src/Grav/Common/Page/Types.php index 69f61e597..f6407cadd 100644 --- a/system/src/Grav/Common/Page/Types.php +++ b/system/src/Grav/Common/Page/Types.php @@ -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); + } }