Added support for relative paths in PageObject::getLevelListing() [#3110]

This commit is contained in:
Matias Griese
2020-12-23 14:09:55 +02:00
parent 0948e9db9d
commit 504a29f496
2 changed files with 20 additions and 1 deletions

View File

@@ -8,6 +8,7 @@
1. [](#improved)
* Make it possible to use an absolute path when loading a blueprint
* Make serialize methods final in `ContentBlock`, `AbstractFile`, `FormTrait`, `ObjectCollectionTrait` and `ObjectTrait`
* Added support for relative paths in `PageObject::getLevelListing()` [#3110](https://github.com/getgrav/grav/issues/3110)
1. [](#bugfix)
* Fixed port issue with `system.custom_base_url`
* Hide errors with `exif_read_data` in `ImageFile`

View File

@@ -439,8 +439,26 @@ class PageObject extends FlexPageObject
public function getLevelListing(array $options): array
{
$index = $this->getFlexDirectory()->getIndex();
if (!is_callable([$index, 'getLevelListing'])) {
return [];
}
return method_exists($index, 'getLevelListing') ? $index->getLevelListing($options) : [];
// Deal with relative paths.
$initial = $options['initial'] ?? null;
$var = $initial ? 'leaf_route' : 'route';
$route = $options[$var] ?? '';
if ($route !== '' && !str_starts_with($route, '/')) {
$filesystem = Filesystem::getInstance();
$route = "/{$this->getKey()}/{$route}";
$route = $filesystem->normalize($route);
$options[$var] = $route;
}
[$status, $message, $response,] = $index->getLevelListing($options);
return [$status, $message, $response, $options[$var] ?? null];
}
/**