Commits

pietschy committed e4e6005

added explicit date nav template

Comments (0)

Files changed (5)

elements/navigation_builder/date_nav/menu.php

+<?php defined('C5_EXECUTE') or die("Access Denied.");
+/** @var NavRoot $navRoot */
+if (!isset($navRoot)) {
+    throw new Exception('Required parameter $navRoot is missing');
+}
+?>
+<ul class="<?=$navRoot->getRenderOption('class','date-nav')?>">
+    <?= $navRoot->renderChildItems() ?>
+</ul>

elements/navigation_builder/date_nav/nav_item.php

+<?php defined('C5_EXECUTE') or die("Access Denied.");
+/** @var NavItem $navItem */
+if (!isset($navItem)) {
+    throw new Exception('Required parameter $navItem is missing');
+}
+$liClassNames = $navItem->getClassNames();
+$anchorClassNames = array();
+$ulClassNames= array();
+
+if ($navItem->isFirstChild()) {
+    $liClassNames[] = 'first-child';
+}
+if ($navItem->isLastChild()) {
+    $liClassNames[] = 'last-child';
+}
+if ($navItem->isCurrent()) {
+    $liClassNames[] = 'nav-selected';
+    $liClassNames[] = 'nav-path-selected';
+}
+if ($navItem->isInPath()) {
+    $liClassNames[] = 'nav-path-selected';
+}
+if (!$navItem->isInPath() && !$navItem->isCurrent())
+{
+    $liClassNames[]= 'closed';
+}
+if ($navItem->hasChildren()) {
+    $liClassNames[] = 'has-children';
+}
+if ($navItem->depth() < 2) {
+    $liClassNames[] = 'level-1';
+}
+if ($navItem->depth() > 1) {
+    $liClassNames[] = 'level-' . $navItem->depth();
+}
+
+$text = $navItem->getName();
+if ($navItem->hasChildren())
+{
+    $text .= " ({$navItem->childCount()})";
+}
+
+?>
+<li class="<?= join(' ', $liClassNames)?>">
+    <a href="<?=$navItem->getURL()?>" class="<?= join(' ', $anchorClassNames)?>" target="<?=$navItem->getTarget()?>"><?=$text?></a>
+    <? if ($navItem->hasChildren()) { ?>
+    <a href="#" class="open-toggle"><span> </span></a>
+    <ul>
+        <? $navItem->renderChildItems() ?>
+    </ul>
+    <? } ?>
+</li>

models/DateNavigationBuilder.php

             $navItem->add(new PageNavItem($page));
         }
 
+        /** @var NavRoot $navRoot */
         $navRoot = new NavRoot("");
 
         // if there's only one year, then just show the months...
         }
 
         $navRoot->configureActivePathFrom(Page::getCurrentPage());
+        $navRoot->setRenderTemplate('date_nav');
+
         return $navRoot;
     }
 

models/NavItem.php

     /** @var String[] */
     private $classNames;
 
+    private $attributes = array();
+
     private $current = false;
     private $inPath = false;
 
     }
 
     /**
-     * DO NOT USE.. use {@link NavRoot::configureActivePathUsing} instead.  This method is only
-     * public due to access limitations in PHP.
+     * DO NOT USE. Use {@link NavRoot::configureActivePathUsing} instead.
+     * This method is only public since I can't call this method from a NavRoot from within
+     * an anonymous function.
      */
     public function _setCurrent($current)
     {
     }
 
     /**
-     * DO NOT USE.. use {@link NavRoot::configureActivePathUsing} instead.  This method is only
-     * public due to access limitations in PHP.
+     * DO NOT USE. Use {@link NavRoot::configureActivePathUsing} instead.
+     * This method is only public since I can't call this method from a NavRoot from within
+     * an anonymous function.
      */
     public function _setInPath($inPath)
     {
         }
     }
 
+    public function setAttribute($name, $value)
+    {
+        $this->attributes[$name] = $value;
+    }
+
+    public function getAttribute($name, $defaultValue = null)
+    {
+        $value = $this->attributes[$name];
+        return !is_null($value) ? $value : $defaultValue;
+    }
+
+    public function hasAttribute($name)
+    {
+        return array_key_exists($this->attributes, $name);
+    }
+
     public function getRenderTemplate()
     {
         return $this->getRoot()->getRenderTemplate();

models/NavRoot.php

             $item->_setInPath(false);
         });
 
-        if (!is_null($activeItem)) {
+        if (!is_null($activeItem))
+        {
             $activeItem->callOnParents(function ($parent)
             {
                 /** @var NavItem $parent */