PHP Class Menu\Items\ItemList

Inheritance: extends Menu\Traits\MenuObject
Mostra file Open project: vespakoen/menu Class Usage Examples

Public Properties

Property Type Description
$name string The name of this ItemList

Public Methods

Method Description
__construct ( $items = [], string $name = null, array $attributes = [], string $element = null ) : void Create a new Item List instance
activePattern ( string $pattern ) : ItemList Add an active pattern to the ItemList instance.
add ( string $url, string $value, ItemList $children = null, array $linkAttributes = [], array $itemAttributes = [], string $itemElement = null, string $beforeContent = null, string $afterContent = null ) : ItemList Add a link item to the ItemList instance.
addContent ( Content $content, ItemList $children = null, array $itemAttributes = [], string $itemElement = null, string $beforeContent = null, string $afterContent = null ) Add content to the ItemList
attach ( ItemList $itemList ) : ItemList Add menu items to another ItemList.
breadcrumbs ( )
find ( $name ) : Vespakoen\Menu\Items\ItemLists | false Find an itemlist by it's name
findActiveItem ( )
findByName ( $name ) : Vespakoen\Menu\Items\ItemLists | false Find an itemlist by it's name
findItemByAttribute ( $key, $value ) : Vespakoen\Menu\Items\Item | false Find an item by an attribute
findItemByUrl ( $url ) : Vespakoen\Menu\Items\Item | false Find an item by it's link's URL
findItemListByName ( $name ) : Vespakoen\Menu\Items\ItemLists | false Find an itemlist by it's name
getAllItemLists ( ) : Vespakoen\Menu\MenuHandler Get all itemlists
getAllItemListsIncludingThisOne ( ) : Vespakoen\Menu\MenuHandler Get all itemslists including this one
getAllItems ( ) : Vespakoen\Menu\MenuHandler Get all items
getElement ( ) : string Get the Item's element
getItemListsAtDepth ( $depth ) : Vespakoen\Menu\MenuHandler Get itemlists at a certain depth
getItemListsAtDepthRange ( $from, $to ) : Vespakoen\Menu\MenuHandler Get itemlists in a range of depths
getItemListsWithDepth ( ) : array Get all itemlists with the depth as key
getItemsAtDepth ( $depth ) : Vespakoen\Menu\MenuHandler Get all items at a certain depth
getItemsAtDepthRange ( $from, $to ) : Vespakoen\Menu\MenuHandler Get items in a range of depths
getItemsByContentType ( string $contentType ) : VEspakoen\Menu\MenuHandler Get items by their content type
getItemsWithDepth ( ) : array Get all items with the depth as key
getName ( ) : string Get the name of the ItemList
getSubmenu ( )
hydrate ( Closure $resolver, Closure $decorator, integer $idField = 'id', $parentIdField = 'parent_id', integer $parentId ) : ItemList Easily create items while looping over DB results that have a reference to the parent (usually via parentId)
map ( $callback )
name ( string $name ) : ItemList Set the name for this ItemList
onItem ( ) : Item Get the last Item
prefix ( string $prefix ) : ItemList Prefix this ItemList with a string
prefixMenuHandler ( boolean $prefixMenuHandler = true ) : ItemList Prefix this ItemList with the name of the ItemList at the very top of the tree
prefixParents ( boolean $prefixParents = true ) : ItemList Prefix this ItemList with the parent ItemList(s) name(s)
raw ( string $raw, ItemList $children = null, array $itemAttributes = [], string $itemElement = null, string $beforeContent = null, string $afterContent = null ) : ItemList Add a raw html item to the ItemList instance.
render ( integer $depth ) : string Get the evaluated string content of the ItemList.
reverse ( )
setElement ( string $element = null ) Set the Item's element
setOption ( string $option, mixed $value ) : Menu\Traits\MenuObject Set a particular option in the array

Protected Methods

Method Description
getItemListsRecursivelyWithDepth ( $itemList, $depth ) : array Get all itemlists for an itemlsit recursively for a specific depth
getItemsRecursivelyWithDepth ( $items, $depth ) : array Get all items for an array of items recursively for a specific depth

Method Details

__construct() public method

Create a new Item List instance
public __construct ( $items = [], string $name = null, array $attributes = [], string $element = null ) : void
$name string The ItemList's name
$attributes array Attributes for the ItemList's HMTL element
$element string The HTML element for the ItemList
return void

activePattern() public method

Add a item to the default menu and set an active class for /user/5/edit Menu::add('user', 'Users')->activePattern('\/user\/\d\/edit');
public activePattern ( string $pattern ) : ItemList
$pattern string
return ItemList

add() public method

Add a item to the default menu Menu::add('home', 'Homepage'); Add a item with a subitem to the default menu Menu::add('home', 'Homepage', Menu::items()->add('home/sub', 'Subitem')); Add a item with attributes for the item's HTML element Menu::add('home', 'Homepage', null, array('class' => 'fancy'));
public add ( string $url, string $value, ItemList $children = null, array $linkAttributes = [], array $itemAttributes = [], string $itemElement = null, string $beforeContent = null, string $afterContent = null ) : ItemList
$url string Url of the link
$value string (H)T(ML) inside of the link
$children ItemList Children
$linkAttributes array Attributes for the link
$itemAttributes array Attributes for the item
$itemElement string The element for the item
$beforeContent string String to add before the link
$afterContent string String to add after the link
return ItemList

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

attach() public method

Attach menu items to the default MenuHandler Menu::attach(Menu::items()->add('home', 'Homepage'));
public attach ( ItemList $itemList ) : ItemList
$itemList ItemList
return ItemList

breadcrumbs() public method

public breadcrumbs ( )

find() public method

alias for findItemListByName
public find ( $name ) : Vespakoen\Menu\Items\ItemLists | false
return Vespakoen\Menu\Items\ItemLists | false

findActiveItem() public method

public findActiveItem ( )

findByName() public method

alias for findItemListByName
public findByName ( $name ) : Vespakoen\Menu\Items\ItemLists | false
return Vespakoen\Menu\Items\ItemLists | false

findItemByAttribute() public method

Find an item by an attribute
public findItemByAttribute ( $key, $value ) : Vespakoen\Menu\Items\Item | false
return Vespakoen\Menu\Items\Item | false

findItemByUrl() public method

Find an item by it's link's URL
public findItemByUrl ( $url ) : Vespakoen\Menu\Items\Item | false
return Vespakoen\Menu\Items\Item | false

findItemListByName() public method

Find an itemlist by it's name
public findItemListByName ( $name ) : Vespakoen\Menu\Items\ItemLists | false
return Vespakoen\Menu\Items\ItemLists | false

getAllItemLists() public method

Get all itemlists
public getAllItemLists ( ) : Vespakoen\Menu\MenuHandler
return Vespakoen\Menu\MenuHandler

getAllItemListsIncludingThisOne() public method

Get all itemslists including this one
public getAllItemListsIncludingThisOne ( ) : Vespakoen\Menu\MenuHandler
return Vespakoen\Menu\MenuHandler

getAllItems() public method

Get all items
public getAllItems ( ) : Vespakoen\Menu\MenuHandler
return Vespakoen\Menu\MenuHandler

getElement() public method

Get the Item's element
public getElement ( ) : string
return string

getItemListsAtDepth() public method

Get itemlists at a certain depth
public getItemListsAtDepth ( $depth ) : Vespakoen\Menu\MenuHandler
return Vespakoen\Menu\MenuHandler

getItemListsAtDepthRange() public method

Get itemlists in a range of depths
public getItemListsAtDepthRange ( $from, $to ) : Vespakoen\Menu\MenuHandler
return Vespakoen\Menu\MenuHandler

getItemListsRecursivelyWithDepth() protected method

Get all itemlists for an itemlsit recursively for a specific depth
protected getItemListsRecursivelyWithDepth ( $itemList, $depth ) : array
return array

getItemListsWithDepth() public method

Get all itemlists with the depth as key
public getItemListsWithDepth ( ) : array
return array

getItemsAtDepth() public method

Get all items at a certain depth
public getItemsAtDepth ( $depth ) : Vespakoen\Menu\MenuHandler
return Vespakoen\Menu\MenuHandler

getItemsAtDepthRange() public method

Get items in a range of depths
public getItemsAtDepthRange ( $from, $to ) : Vespakoen\Menu\MenuHandler
return Vespakoen\Menu\MenuHandler

getItemsByContentType() public method

Get items by their content type
public getItemsByContentType ( string $contentType ) : VEspakoen\Menu\MenuHandler
$contentType string The full object name
return VEspakoen\Menu\MenuHandler

getItemsRecursivelyWithDepth() protected method

Get all items for an array of items recursively for a specific depth
protected getItemsRecursivelyWithDepth ( $items, $depth ) : array
return array

getItemsWithDepth() public method

Get all items with the depth as key
public getItemsWithDepth ( ) : array
return array

getName() public method

Get the name of the ItemList
public getName ( ) : string
return string Name of the ItemList

getSubmenu() public method

public getSubmenu ( )

hydrate() public method

Menu::hydrate(function($parentId) { return Page::where('parent_id', $parentId) ->get(); }, function($children, $page) { $children->add($page->slug, $page->name); });
public hydrate ( Closure $resolver, Closure $decorator, integer $idField = 'id', $parentIdField = 'parent_id', integer $parentId ) : ItemList
$resolver Closure the callback to resolve results for a given parentId
$decorator Closure the callback that modifies the ItemList for the given node
$idField integer the id column that matches with the parentId
$parentId integer the parentId to start hydrating from
return ItemList the

map() public method

public map ( $callback )

name() public method

Set the name for this ItemList
public name ( string $name ) : ItemList
$name string
return ItemList

onItem() public method

Get the last Item
public onItem ( ) : Item
return Item

prefix() public method

Prefix this ItemList with a string
public prefix ( string $prefix ) : ItemList
$prefix string
return ItemList

prefixMenuHandler() public method

Prefix this ItemList with the name of the ItemList at the very top of the tree
public prefixMenuHandler ( boolean $prefixMenuHandler = true ) : ItemList
$prefixMenuHandler boolean
return ItemList

prefixParents() public method

Prefix this ItemList with the parent ItemList(s) name(s)
public prefixParents ( boolean $prefixParents = true ) : ItemList
$prefixParents boolean
return ItemList

raw() public method

Add a raw item to the default main menu Menu::raw('');
public raw ( string $raw, ItemList $children = null, array $itemAttributes = [], string $itemElement = null, string $beforeContent = null, string $afterContent = null ) : ItemList
$raw string The raw content
$children ItemList Children
$itemAttributes array The item attributes
$itemElement string The item element
$beforeContent string String to add before the raw content
$afterContent string String to add after the raw content
return ItemList

render() public method

Get the evaluated string content of the ItemList.
public render ( integer $depth ) : string
$depth integer The depth at which the ItemList should be rendered
return string

reverse() public method

public reverse ( )

setElement() public method

Set the Item's element
public setElement ( string $element = null )
$element string

setOption() public method

Set a particular option in the array
public setOption ( string $option, mixed $value ) : Menu\Traits\MenuObject
$option string The option
$value mixed Its new value
return Menu\Traits\MenuObject

Property Details

$name public_oe property

The name of this ItemList
public string $name
return string