Menu\Items\ItemList::addContent PHP Method

addContent() public method

Add content to the ItemList
public addContent ( Content $content, ItemList $children = null, array $itemAttributes = [], string $itemElement = null, string $beforeContent = null, string $afterContent = null )
$content Content Content object
$children ItemList Children
$itemAttributes array Attributes for the item (li)
$itemElement string Element for the item (li is default)
$beforeContent string String to add before the content
$afterContent string String to add after the content
    public function addContent($content, $children = null, $itemAttributes = array(), $itemElement = null, $beforeContent = null, $afterContent = null)
    {
        $item = new Item($this, $content, $children, $itemElement, $beforeContent, $afterContent);
        $item->setAttributes($itemAttributes);
        // Set Item as parent of its children
        if (!is_null($children)) {
            $children->setParent($item);
        }
        $this->setChild($item);
        return $item;
    }

Usage Example

Ejemplo n.º 1
0
 public function breadcrumbs()
 {
     // Collect all items
     $activeItem = $this->findActiveItem();
     $separator = $this->getOption('item_list.breadcrumb_separator');
     // Make the breadcrumbs
     $itemList = new ItemList(array(), 'breadcrumbs');
     // Fill her up if we found the active link
     if (!is_null($activeItem)) {
         // Add the found item
         $itemList->addContent($activeItem->getContent());
         // Loop throught the parents until we hit the root
         while ($nextItem = $activeItem->getParent()) {
             if (is_null($nextItem->getParent())) {
                 break;
             }
             // Add a separator and the link
             if (!empty($separator)) {
                 $itemList->raw($separator);
             }
             $itemList->addContent($nextItem->getParent()->getContent());
             // Set the activeItem for the next iteration
             $activeItem = $nextItem->getParent();
         }
     }
     // Correct order
     $itemList->reverse();
     return $itemList;
 }