Register all page types into blueprint://pages stream

This commit is contained in:
Matias Griese
2018-10-01 21:26:36 +03:00
parent 760c3e869f
commit 920b0fcb2e
3 changed files with 18 additions and 6 deletions

View File

@@ -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

View File

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

View File

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