PHP Trait NestedCollection, vanilla

Since: 2.3
Author: Becky Van Bussel ([email protected])
Afficher le fichier Open project: vanilla/vanilla

Méthodes publiques

Свойство 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

Свойство Type Description
$allowedItemModifiers The item modifiers allowed to be passed in the modifiers array.

Méthodes publiques

Méthode 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 )

Méthodes protégées

Méthode 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 méthode

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').
Résultat object $this The calling object.

addDividerIf() public méthode

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').
Résultat object $this The calling object.

addGroup() public méthode

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.
Résultat SortableModule $this The calling object.

addGroupIf() public méthode

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.
Résultat object $this The calling object.

addItem() protected méthode

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 méthode

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 méthode

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.
Résultat object $this The calling object.

buildCssClass() protected méthode

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.
Résultat string The generated CSS class.

flattenArray() protected méthode

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

getHighlightRoute() public méthode

public getHighlightRoute ( ) : string
Résultat string

isActive() protected méthode

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

isAllowed() protected méthode

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.
Résultat boolean Whether the item has permission to be added to the items list.

prepare() public méthode

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

prepareData() protected méthode

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 méthode

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 méthode

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

setHighlightRoute() public méthode

public setHighlightRoute ( string $highlightRoute )
$highlightRoute string

sortItems() protected méthode

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

sortItemsOrder() protected méthode

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.
Résultat number

touchKey() protected méthode

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