From b25eeb95865d17feee382d0b84387b32f451cf27 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Thu, 12 May 2016 17:40:51 +0300 Subject: [PATCH] Add support for extending system page types --- system/src/Grav/Common/Data/Blueprint.php | 56 ++++++++++++---------- system/src/Grav/Common/Data/Blueprints.php | 2 + 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/system/src/Grav/Common/Data/Blueprint.php b/system/src/Grav/Common/Data/Blueprint.php index 1dbc39fb5..9224055fd 100644 --- a/system/src/Grav/Common/Data/Blueprint.php +++ b/system/src/Grav/Common/Data/Blueprint.php @@ -130,35 +130,41 @@ class Blueprint extends BlueprintForm */ protected function getFiles($path, $context = null) { - if (is_string($path) && !strpos($path, '://')) { - // Resolve filename. - if (isset($this->overrides[$path])) { - $path = $this->overrides[$path]; - } else { - if ($context === null) { - $context = $this->context; - } - if ($context && $context[strlen($context)-1] !== '/') { - $context .= '/'; - } - $path = $context . $path; + /** @var UniformResourceLocator $locator */ + $locator = Grav::instance()['locator']; - if (!preg_match('/\.yaml$/', $path)) { - $path .= '.yaml'; - } + if (is_string($path) && !$locator->isStream($path)) { + // Find path overrides. + $paths = isset($this->overrides[$path]) ? (array) $this->overrides[$path] : []; + + // Add path pointing to default context. + if ($context === null) { + $context = $this->context; + } + if ($context && $context[strlen($context)-1] !== '/') { + $context .= '/'; + } + $path = $context . $path; + + if (!preg_match('/\.yaml$/', $path)) { + $path .= '.yaml'; + } + + $paths[] = $path; + } else { + $paths = (array) $path; + } + + $files = []; + foreach ($paths as $lookup) { + if (is_string($lookup) && strpos($lookup, '://')) { + $files = array_merge($files, $locator->findResources($lookup)); + } else { + $files[] = $lookup; } } - if (is_string($path) && strpos($path, '://')) { - /** @var UniformResourceLocator $locator */ - $locator = Grav::instance()['locator']; - - $files = array_unique($locator->findResources($path)); - } else { - $files = (array) $path; - } - - return $files; + return array_values(array_unique($files)); } /** diff --git a/system/src/Grav/Common/Data/Blueprints.php b/system/src/Grav/Common/Data/Blueprints.php index f2f6a0224..2d59f650a 100644 --- a/system/src/Grav/Common/Data/Blueprints.php +++ b/system/src/Grav/Common/Data/Blueprints.php @@ -87,7 +87,9 @@ class Blueprints $blueprint = new Blueprint($name); if (is_array($this->search) || is_object($this->search)) { + // Page types. $blueprint->setOverrides($this->search); + $blueprint->setContext('blueprints://pages'); } else { $blueprint->setContext($this->search); }