Пример #1
0
 /**
  * Add classes to the current link and its ancestors
  * @param \Laasti\Navigation\MenuLink $link
  */
 protected function activate(MenuLink $link)
 {
     $link->setAttribute('class', $link->getAttribute('class') . ' ' . $this->classes['active']);
     $link->setContainerAttribute('class', $link->getContainerAttribute('class') . ' ' . $this->classes['container_active']);
     $parent = $link->getParent();
     $level = 0;
     while ($parent instanceof Menu || $parent instanceof MenuLink) {
         if ($parent instanceof Menu) {
             $parent = $parent->getParent();
             continue;
         }
         if (!$level) {
             $parent->setAttribute('class', $parent->getAttribute('class') . ' ' . $this->classes['parent']);
             $parent->setContainerAttribute('class', $parent->getContainerAttribute('class') . ' ' . $this->classes['container_parent']);
         } else {
             $parent->setAttribute('class', $parent->getAttribute('class') . ' ' . $this->classes['ancestor']);
             $parent->setContainerAttribute('class', $parent->getContainerAttribute('class') . ' ' . $this->classes['container_ancestor']);
         }
         $level++;
         $parent = $parent->getParent();
     }
 }