From 920b0fcb2ebadfe8cc7597f6571a12ca2650f6ab Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Mon, 1 Oct 2018 21:26:36 +0300 Subject: [PATCH] Register all page types into `blueprint://pages` stream --- CHANGELOG.md | 1 + system/src/Grav/Common/Page/Pages.php | 13 ++++++++++++- system/src/Grav/Common/Page/Types.php | 10 +++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 215186a42..20537b707 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ * Added support for hiding form fields in blueprints by using dynamic property like `security@: admin.foobar`, `scope@: object` or `scope-ignore@: object` to any field 1. [](#improved) * Doctrine filecache is now namespaced with prefix to support purging + * Register all page types into `blueprint://pages` stream # v1.5.2 ## mm/dd/2018 diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index ac0e41cb0..57f2fb4f2 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -710,7 +710,6 @@ class Pages public static function getTypes() { if (!self::$types) { - $grav = Grav::instance(); $scanBlueprintsAndTemplates = function () use ($grav) { @@ -748,6 +747,18 @@ class Pages $scanBlueprintsAndTemplates(); } + // Register custom paths to the locator. + $locator = $grav['locator']; + foreach (self::$types as $type => $paths) { + foreach ($paths as $k => $path) { + if (strpos($path, 'blueprints://') === 0) { + unset($paths[$k]); + } + } + if ($paths) { + $locator->addPath('blueprints', "pages/$type.yaml", $paths); + } + } } return self::$types; diff --git a/system/src/Grav/Common/Page/Types.php b/system/src/Grav/Common/Page/Types.php index 436d4f835..10b07beda 100644 --- a/system/src/Grav/Common/Page/Types.php +++ b/system/src/Grav/Common/Page/Types.php @@ -33,7 +33,7 @@ class Types implements \ArrayAccess, \Iterator, \Countable } if (!$blueprint && $this->systemBlueprints) { - $blueprint = isset($this->systemBlueprints[$type]) ? $this->systemBlueprints[$type] : $this->systemBlueprints['default']; + $blueprint = $this->systemBlueprints[$type] ?? $this->systemBlueprints['default']; } if ($blueprint) { @@ -43,7 +43,7 @@ class Types implements \ArrayAccess, \Iterator, \Countable public function scanBlueprints($uri) { - if (!is_string($uri)) { + if (!\is_string($uri)) { throw new \InvalidArgumentException('First parameter must be URI'); } @@ -63,7 +63,7 @@ class Types implements \ArrayAccess, \Iterator, \Countable public function scanTemplates($uri) { - if (!is_string($uri)) { + if (!\is_string($uri)) { throw new \InvalidArgumentException('First parameter must be URI'); } @@ -96,7 +96,7 @@ class Types implements \ArrayAccess, \Iterator, \Countable if (strpos($name, '/')) { continue; } - $list[$name] = ucfirst(strtr($name, '_', ' ')); + $list[$name] = ucfirst(str_replace('_', ' ', $name)); } ksort($list); return $list; @@ -109,7 +109,7 @@ class Types implements \ArrayAccess, \Iterator, \Countable if (strpos($name, 'modular/') !== 0) { continue; } - $list[$name] = trim(ucfirst(strtr(basename($name), '_', ' '))); + $list[$name] = ucfirst(trim(str_replace('_', ' ', basename($name)))); } ksort($list); return $list;