PHP Trait NestedCollection, vanilla

Since: 2.3
Author: Becky Van Bussel ([email protected])
ファイルを表示 Open project: vanilla/vanilla

Public Properties

Property Type Description
$activeCssClass The css class to add to active items and groups.
$dividerCssClassPrefix CSS prefix for a divider item.
$headerCssClassPrefix CSS prefix for a header item.
$items List of items to sort.
$linkCssClassPrefix CSS prefix for a link item.
$useCssPrefix Whether to use CSS prefixes on the generated CSS classes for the items.

Protected Properties

Property Type Description
$allowedItemModifiers The item modifiers allowed to be passed in the modifiers array.

Public Methods

Method Description
addDivider ( string $key = '', string $cssClass = '', array | integer $sort = [] ) : object Add a divider to the items array.
addDividerIf ( boolean | string | array $isAllowed = true, string $key = '', string $cssClass = '', array | integer $sort = [] ) : object Add a divider to the items array if it satisfies the $isAllowed condition.
addGroup ( string $text = '', string $key = '', string $cssClass = '', array | integer $sort = [], array $modifiers = [] ) : SortableModule Add a group to the items array.
addGroupIf ( boolean | string | array $isAllowed = true, string $text = '', string $key = '', string $cssClass = '', array | integer $sort = [], array $modifiers = [] ) : object Add a group to the items array if it satisfies the $isAllowed condition.
addItemModifiers ( array &$item, array $modifiers ) Adds the attributes in the modifiers array to the item.
addLink ( string $text, string $url, string $key = '', string $cssClass = '', array | integer $sort = [], array $modifiers = [], boolean $disabled = false ) Add a link to the items array.
addLinkIf ( boolean | string | array $isAllowed = true, string $text, string $url, string $key = '', string $cssClass = '', array | integer $sort = [], array $modifiers = [], boolean $disabled = false ) : object Add a link to the items array if it satisfies the $isAllowed condition.
getHighlightRoute ( ) : string
prepare ( ) : boolean Prepares the items array for output by sorting and optionally flattening.
removeItem ( string $key ) Remove an item from the nested set.
setForceDivider ( boolean $forceDivider )
setHighlightRoute ( string $highlightRoute )

Protected Methods

Method Description
addItem ( string $type, array $item ) Add an item to the items array.
buildCssClass ( string $prefix, array $item ) : string Builds a CSS class for an item, based on the 'key' property of the item.
flattenArray ( array $items ) : array Creates a flattened array of menu items.
isActive ( array $item ) : boolean Checks whether the current request url matches an item's link url.
isAllowed ( boolean | string | array $isAllowed ) : boolean Checks whether an item can be added to the items list by returning it if it is already a boolean, or checking the permission if it is a string or array.
prepareData ( array &$items ) Performs post-sort operations to the items array.
sortItems ( array &$items ) Recursive function to sort the items in a given array.
sortItemsOrder ( array $item, array $items, integer $depth ) : number Get the sort order of an item in the items array.
touchKey ( array &$item ) Generate a key for an item if one does not exist, and add the property to the item.

Method Details

addDivider() public method

Add a divider to the items array.
public addDivider ( string $key = '', string $cssClass = '', array | integer $sort = [] ) : object
$key string The item's key (for sorting and CSS targeting).
$cssClass string The divider's CSS class.
$sort array | integer Either a numeric sort position or and array in the style: array('before|after', 'key').
return object $this The calling object.

addDividerIf() public method

Add a divider to the items array if it satisfies the $isAllowed condition.
public addDividerIf ( boolean | string | array $isAllowed = true, string $key = '', string $cssClass = '', array | integer $sort = [] ) : object
$isAllowed boolean | string | array Either a boolean to indicate whether to actually add the item or a permission string or array of permission strings (full match) to check.
$key string The item's key (for sorting and CSS targeting).
$cssClass string The divider's CSS class.
$sort array | integer Either a numeric sort position or and array in the style: array('before|after', 'key').
return object $this The calling object.

addGroup() public method

Add a group to the items array.
public addGroup ( string $text = '', string $key = '', string $cssClass = '', array | integer $sort = [], array $modifiers = [] ) : SortableModule
$text string The display text for the group header.
$key string The item's key (for sorting and CSS targeting).
$cssClass string The group header's CSS class.
$sort array | integer Either a numeric sort position or and array in the style: array('before|after', 'key').
$modifiers array List of attribute => value, where the attribute is in $this->allowedItemModifiers. - **popinRel**: string - Endpoint for a popin. - **badge**: string - Info to put into a badge, usually a number. - **icon**: string - Name of the icon for the item, excluding the 'icon-' prefix.
return SortableModule $this The calling object.

addGroupIf() public method

Add a group to the items array if it satisfies the $isAllowed condition.
public addGroupIf ( boolean | string | array $isAllowed = true, string $text = '', string $key = '', string $cssClass = '', array | integer $sort = [], array $modifiers = [] ) : object
$isAllowed boolean | string | array Either a boolean to indicate whether to actually add the item or a permission string or array of permission strings (full match) to check.
$text string The display text for the group header.
$key string The item's key (for sorting and CSS targeting).
$cssClass string The group header's CSS class.
$sort array | integer Either a numeric sort position or and array in the style: array('before|after', 'key').
$modifiers array List of attribute => value, where the attribute is in $this->allowedItemModifiers. - **popinRel**: string - Endpoint for a popin. - **badge**: string - Info to put into a badge, usually a number. - **icon**: string - Name of the icon for the item, excluding the 'icon-' prefix.
return object $this The calling object.

addItem() protected method

Add an item to the items array.
protected addItem ( string $type, array $item )
$type string The type of the item: link, group or divider.
$item array The item to add to the array.

addItemModifiers() public method

Constrains the modifier to those defined in $this->allowedItemModifiers.
public addItemModifiers ( array &$item, array $modifiers )
$item array The item to modify.
$modifiers array The modifiers to add to the item.

addLinkIf() public method

Add a link to the items array if it satisfies the $isAllowed condition.
public addLinkIf ( boolean | string | array $isAllowed = true, string $text, string $url, string $key = '', string $cssClass = '', array | integer $sort = [], array $modifiers = [], boolean $disabled = false ) : object
$isAllowed boolean | string | array Either a boolean to indicate whether to actually add the item or a permission string or array of permission strings (full match) to check.
$text string The display text for the link.
$url string The destination url for the link.
$key string The item's key (for sorting and CSS targeting).
$cssClass string The link's CSS class.
$sort array | integer Either a numeric sort position or and array in the style: array('before|after', 'key').
$modifiers array List of attribute => value, where the attribute is in $this->allowedItemModifiers. - **popinRel**: string - Endpoint for a popin. - **badge**: string - Info to put into a badge, usually a number. - **icon**: string - Name of the icon for the item, excluding the 'icon-' prefix.
$disabled boolean Whether to disable the link.
return object $this The calling object.

buildCssClass() protected method

Optionally prepends a prefix to generated class names.
protected buildCssClass ( string $prefix, array $item ) : string
$prefix string The optional prefix to add to class name.
$item array The item to generate CSS class for.
return string The generated CSS class.

flattenArray() protected method

Useful for lists like dropdown menu, where nesting lists is not necessary.
protected flattenArray ( array $items ) : array
$items array The item list to flatten.
return array The flattened items list.

getHighlightRoute() public method

public getHighlightRoute ( ) : string
return string

isActive() protected method

Checks whether the current request url matches an item's link url.
protected isActive ( array $item ) : boolean
$item array The item to check.
return boolean Whether the current request url matches an item's link url.

isAllowed() protected method

Checks whether an item can be added to the items list by returning it if it is already a boolean, or checking the permission if it is a string or array.
protected isAllowed ( boolean | string | array $isAllowed ) : boolean
$isAllowed boolean | string | array Either a boolean to indicate whether to actually add the item or a permission string or array of permission strings (full match) to check.
return boolean Whether the item has permission to be added to the items list.

prepare() public method

Prepares the items array for output by sorting and optionally flattening.
public prepare ( ) : boolean
return boolean Whether to render the module.

prepareData() protected method

Removes empty groups, removes the '_sort' and 'key' attributes and bubbles up the active css class.
protected prepareData ( array &$items )
$items array The item list to parse.

removeItem() public method

Remove an item from the nested set.
public removeItem ( string $key )
$key string The key of the item to remove, separated by dots.

setForceDivider() public method

public setForceDivider ( boolean $forceDivider )
$forceDivider boolean Whether to separate groups with a
element. Only supported for flattened lists.

setHighlightRoute() public method

public setHighlightRoute ( string $highlightRoute )
$highlightRoute string

sortItems() protected method

Recursive function to sort the items in a given array.
protected sortItems ( array &$items )
$items array The items to sort.

sortItemsOrder() protected method

This function looks at the following keys: - **sort (numeric)**: A specific numeric sort was provided. - **sort array('before|after', 'key')**: You can specify that the item is before or after another item. - **_sort**: The order the item was added is used.
protected sortItemsOrder ( array $item, array $items, integer $depth ) : number
$item array The item to get the sort order from.
$items array The entire list of items.
$depth integer The current recursive depth used to prevent infinite recursion.
return number

touchKey() protected method

Generate a key for an item if one does not exist, and add the property to the item.
protected touchKey ( array &$item )
$item array The item to generate and add a key for.

Property Details

$activeCssClass public_oe property

The css class to add to active items and groups.
public $activeCssClass

$allowedItemModifiers protected_oe property

The item modifiers allowed to be passed in the modifiers array.
protected $allowedItemModifiers

$dividerCssClassPrefix public_oe property

CSS prefix for a divider item.
public $dividerCssClassPrefix

$headerCssClassPrefix public_oe property

CSS prefix for a header item.
public $headerCssClassPrefix

$items public_oe property

List of items to sort.
public $items

$linkCssClassPrefix public_oe property

CSS prefix for a link item.
public $linkCssClassPrefix

$useCssPrefix public_oe property

Whether to use CSS prefixes on the generated CSS classes for the items.
public $useCssPrefix