Todaymade\Daux\Format\HTML\Template::buildNavigation PHP Метод

buildNavigation() приватный Метод

private buildNavigation ( Directory $tree, $path, $current_url, $base_page, $mode )
$tree Todaymade\Daux\Tree\Directory
    private function buildNavigation(Directory $tree, $path, $current_url, $base_page, $mode)
    {
        $nav = [];
        foreach ($tree->getEntries() as $node) {
            $url = $node->getUri();
            if ($node instanceof Content) {
                if ($node->isIndex()) {
                    continue;
                }
                $link = $path === '' ? $url : $path . '/' . $url;
                $nav[] = ['title' => $node->getTitle(), 'href' => $base_page . $link, 'class' => $current_url === $link ? 'Nav__item--active' : ''];
            } elseif ($node instanceof Directory) {
                if (!$node->hasContent()) {
                    continue;
                }
                $link = $path === '' ? $url : $path . '/' . $url;
                $folder = ['title' => $node->getTitle(), 'class' => strpos($current_url, $link) === 0 ? 'Nav__item--open' : ''];
                if ($index = $node->getIndexPage()) {
                    $folder['href'] = $base_page . $index->getUrl();
                }
                //Child pages
                $new_path = $path === '' ? $url : $path . '/' . $url;
                $folder['children'] = $this->buildNavigation($node, $new_path, $current_url, $base_page, $mode);
                if (!empty($folder['children'])) {
                    $folder['class'] .= ' has-children';
                }
                $nav[] = $folder;
            }
        }
        return $nav;
    }