diff --git a/system/src/Grav/Common/Page/Types.php b/system/src/Grav/Common/Page/Types.php index 9efa37fcf..7b3c86177 100644 --- a/system/src/Grav/Common/Page/Types.php +++ b/system/src/Grav/Common/Page/Types.php @@ -19,14 +19,18 @@ class Types implements \ArrayAccess, \Iterator, \Countable public function register($type, $blueprint = null) { - if (!$blueprint && $this->systemBlueprints && isset($this->systemBlueprints[$type])) { - $useBlueprint = $this->systemBlueprints[$type]; - } else { - $useBlueprint = $blueprint; + if (!isset($this->items[$type])) { + $this->items[$type] = []; + } elseif (!$blueprint) { + return; } - if ($blueprint || empty($this->items[$type])) { - $this->items[$type] = $useBlueprint; + if (!$blueprint && $this->systemBlueprints) { + $blueprint = isset($this->systemBlueprints[$type]) ? $this->systemBlueprints[$type] : $this->systemBlueprints['default']; + } + + if ($blueprint) { + array_unshift($this->items[$type], $blueprint); } } @@ -36,7 +40,16 @@ class Types implements \ArrayAccess, \Iterator, \Countable throw new \InvalidArgumentException('First parameter must be URI'); } - $this->items = $this->findBlueprints($uri) + $this->items; + if (!$this->systemBlueprints) { + $this->systemBlueprints = $this->findBlueprints('blueprints://pages'); + + // Register default by default. + $this->register('default'); + } + + foreach ($this->findBlueprints($uri) as $type => $blueprint) { + $this->register($type, $blueprint); + } } public function scanTemplates($uri) @@ -55,13 +68,6 @@ class Types implements \ArrayAccess, \Iterator, \Countable 'recursive' => false ]; - if (!$this->systemBlueprints) { - $this->systemBlueprints = $this->findBlueprints('blueprints://pages'); - } - - // register default by default - $this->register('default'); - foreach (Folder::all($uri, $options) as $type) { $this->register($type); }