RainLab\Pages\Classes\PageList::getPageTree PHP Method

getPageTree() public method

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'=>[...])
    public function getPageTree($skipCache = false)
    {
        $pages = $this->listPages($skipCache);
        $config = $this->getPagesConfig();
        $iterator = function ($configPages) use(&$iterator, &$pages) {
            $result = [];
            foreach ($configPages as $fileName => $subpages) {
                $pageObject = null;
                foreach ($pages as $page) {
                    if ($page->getBaseFileName() == $fileName) {
                        $pageObject = $page;
                        break;
                    }
                }
                if ($pageObject === null) {
                    continue;
                }
                $result[] = (object) ['page' => $pageObject, 'subpages' => $iterator($subpages)];
            }
            return $result;
        };
        return $iterator($config['static-pages']);
    }

Usage Example

Esempio n. 1
0
 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;
 }
All Usage Examples Of RainLab\Pages\Classes\PageList::getPageTree