Пример #1
0
 /**
  * Renders menu tree. Internal method.
  *
  * @param MenuItem  $item        Menu item
  * @param integer $depth         The depth of children to render
  * @param boolean $renderAsChild Render with attributes on the li (true) or the ul around the children (false)
  *
  * @return string
  */
 protected function doRender(MenuItem $item, $depth = null, $renderAsChild = false)
 {
     /**
      * Return an empty string if any of the following are true:
      *   a) The menu has no children eligible to be displayed
      *   b) The depth is 0
      *   c) This menu item has been explicitly set to hide its children
      */
     if (!$item->hasChildren() || $depth === 0 || !$item->getShowChildren()) {
         return '';
     }
     if ($renderAsChild) {
         $attributes = array('class' => 'menu_level_' . $item->getLevel());
     } else {
         $attributes = $item->getAttributes();
     }
     // render children with a depth - 1
     $childDepth = $depth === null ? null : $depth - 1;
     $html = $this->format('<ul' . $this->renderHtmlAttributes($attributes) . '>', 'ul', $item->getLevel());
     $html .= $this->renderChildren($item, $childDepth);
     $html .= $this->format('</ul>', 'ul', $item->getLevel());
     return $html;
 }
Пример #2
0
 /**
  * Moves child to specified position. Rearange other children accordingly.
  *
  * @param MenuItem $child Child to move.
  * @param numeric $position Position to move child to.
  */
 public function moveChildToPosition(MenuItem $child, $position)
 {
     $name = $child->getName();
     $order = array_keys($this->children);
     $oldPosition = array_search($name, $order);
     unset($order[$oldPosition]);
     $order = array_values($order);
     array_splice($order, $position, 0, $name);
     $this->reorderChildren($order);
 }
Пример #3
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testReorderingWithTooManyItemNames()
 {
     $menu = new MenuItem('root');
     $menu->addChild('c1');
     $menu->reorderChildren(array('c1', 'c3'));
 }