mirror of
https://github.com/getgrav/grav.git
synced 2026-02-19 04:58:21 +01:00
Use Flex Root page in frontend as well
This commit is contained in:
@@ -115,7 +115,6 @@ class PageIndex extends FlexPageIndex
|
||||
$storage = $directory->getStorage();
|
||||
|
||||
$defaults = [
|
||||
'root' => true,
|
||||
'header' => [
|
||||
'routable' => false,
|
||||
'permissions' => [
|
||||
@@ -145,6 +144,7 @@ class PageIndex extends FlexPageIndex
|
||||
|
||||
/** @var PageObject $root */
|
||||
$root = $this->getFlexDirectory()->createObject($row, '/', false);
|
||||
$root->root = true;
|
||||
|
||||
$this->_root = $root;
|
||||
}
|
||||
|
||||
@@ -340,7 +340,7 @@ class PageObject extends FlexPageObject
|
||||
// Deal with ordering=bool and order=page1,page2,page3.
|
||||
if (array_key_exists('ordering', $elements) && array_key_exists('order', $elements)) {
|
||||
$ordering = (bool)($elements['ordering'] ?? false);
|
||||
$slug = preg_replace(PAGE_ORDER_PREFIX_REGEX, '', $this->getProperty('folder'));
|
||||
$slug = preg_replace(static::PAGE_ORDER_PREFIX_REGEX, '', $this->getProperty('folder'));
|
||||
$list = !empty($elements['order']) ? explode(',', $elements['order']) : [];
|
||||
if ($ordering) {
|
||||
$order = array_search($slug, $list, true);
|
||||
|
||||
@@ -307,6 +307,22 @@ class PageStorage extends FolderStorage
|
||||
unset($row['parent_key'], $row['order'], $row['folder'], $row['template'], $row['lang']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @return array
|
||||
*/
|
||||
protected function loadRow(string $key): ?array
|
||||
{
|
||||
$data = parent::loadRow($key);
|
||||
|
||||
// Special case for root page.
|
||||
if ($key === '' && null !== $data) {
|
||||
$data['root'] = true;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Page storage supports moving and copying the pages and their languages.
|
||||
*
|
||||
|
||||
@@ -39,6 +39,10 @@ trait PageRoutableTrait
|
||||
throw new \RuntimeException('Not Implemented');
|
||||
}
|
||||
|
||||
if ($this->root()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Pages $pages */
|
||||
$pages = Grav::instance()['pages'];
|
||||
|
||||
|
||||
@@ -1377,7 +1377,7 @@ class Pages
|
||||
$debugger = $this->grav['debugger'];
|
||||
$debugger->addMessage('Page cache missed, rebuilding Flex Pages..');
|
||||
|
||||
$root = $this->buildRootPage();
|
||||
$root = $collection->getRoot();
|
||||
$root_path = $root->path();
|
||||
$this->routes = [];
|
||||
$this->instances = [$root_path => $root];
|
||||
|
||||
@@ -43,6 +43,7 @@ class FlexPageObject extends FlexObject implements PageInterface, MediaManipulat
|
||||
use FlexMediaTrait;
|
||||
|
||||
const PAGE_ORDER_REGEX = '/^(\d+)\.(.*)$/u';
|
||||
const PAGE_ORDER_PREFIX_REGEX = '/^[0-9]+\./u';
|
||||
|
||||
/** @var array|null */
|
||||
protected $_reorder;
|
||||
|
||||
@@ -311,7 +311,7 @@ trait PageContentTrait
|
||||
return null;
|
||||
}
|
||||
|
||||
$folder = preg_replace(PAGE_ORDER_PREFIX_REGEX, '', $folder);
|
||||
$folder = preg_replace(static::PAGE_ORDER_PREFIX_REGEX, '', $folder);
|
||||
if (null === $folder) {
|
||||
return null;
|
||||
}
|
||||
@@ -555,7 +555,7 @@ trait PageContentTrait
|
||||
case 'folder':
|
||||
$folder = $this->folder();
|
||||
|
||||
return null !== $folder ? preg_replace(PAGE_ORDER_PREFIX_REGEX, '', $folder) : '';
|
||||
return null !== $folder ? preg_replace(static::PAGE_ORDER_PREFIX_REGEX, '', $folder) : '';
|
||||
case 'slug':
|
||||
return $this->slug();
|
||||
case 'published':
|
||||
|
||||
@@ -23,6 +23,9 @@ use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
*/
|
||||
trait PageRoutableTrait
|
||||
{
|
||||
/** @var bool */
|
||||
protected $root = false;
|
||||
|
||||
/** @var string */
|
||||
private $_route;
|
||||
/** @var string */
|
||||
@@ -186,6 +189,10 @@ trait PageRoutableTrait
|
||||
return $route;
|
||||
}
|
||||
|
||||
if ($this->root()) {
|
||||
return '/';
|
||||
}
|
||||
|
||||
// Root and orphan nodes have no route.
|
||||
$parent = $this->parent();
|
||||
if (!$parent) {
|
||||
@@ -404,6 +411,10 @@ trait PageRoutableTrait
|
||||
throw new \RuntimeException(__METHOD__ . '(PageInterface): Not Implemented');
|
||||
}
|
||||
|
||||
if ($this->root()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$directory = $this->getFlexDirectory();
|
||||
$parentKey = ltrim(dirname("/{$this->getKey()}"), '/');
|
||||
if ($parentKey) {
|
||||
@@ -418,7 +429,7 @@ trait PageRoutableTrait
|
||||
|
||||
$index = $directory->getIndex();
|
||||
|
||||
return !$this->root() && method_exists($index, 'getRoot') ? $index->getRoot() : null;
|
||||
return method_exists($index, 'getRoot') ? $index->getRoot() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -520,7 +531,7 @@ trait PageRoutableTrait
|
||||
*/
|
||||
public function root(): bool
|
||||
{
|
||||
return $this->getKey() === '/';
|
||||
return $this->root === true || $this->getKey() === '/';
|
||||
}
|
||||
|
||||
abstract protected function loadHeaderProperty(string $property, $var, callable $filter);
|
||||
|
||||
Reference in New Issue
Block a user