The method uses the theme's meta/static-pages.yaml file to build the hierarchy. The pages are returned
in the order defined in the YAML file. The result of the method is used for building the back-end UI
and for generating the menus.
public getPageTree ( boolean $skipCache = false ) : array | ||
$skipCache | boolean | Indicates if objects should be reloaded from the disk bypassing the cache. |
return | array | Returns a nested array of objects: object('page': $pageObj, 'subpages'=>[...]) |
protected function getData() { $pageList = new StaticPageList($this->theme); $pages = $pageList->getPageTree(true); $searchTerm = Str::lower($this->getSearchTerm()); if (strlen($searchTerm)) { $words = explode(' ', $searchTerm); $iterator = function ($pages) use(&$iterator, $words) { $result = []; foreach ($pages as $page) { if ($this->textMatchesSearch($words, $this->subtreeToText($page))) { $result[] = (object) ['page' => $page->page, 'subpages' => $iterator($page->subpages)]; } } return $result; }; $pages = $iterator($pages); } return $pages; }
/** * Returns a list of options for the Reference drop-down menu in the * menu item configuration form, when the Static Page item type is selected. * @return array Returns an array */ protected static function listStaticPageMenuOptions() { $theme = Theme::getEditTheme(); $pageList = new PageList($theme); $pageTree = $pageList->getPageTree(true); $iterator = function ($pages) use(&$iterator) { $result = []; foreach ($pages as $pageInfo) { $pageName = $pageInfo->page->getViewBag()->property('title'); $fileName = $pageInfo->page->getBaseFileName(); if (!$pageInfo->subpages) { $result[$fileName] = $pageName; } else { $result[$fileName] = ['title' => $pageName, 'items' => $iterator($pageInfo->subpages)]; } } return $result; }; return $iterator($pageTree); }