PHP Class ElggMenuItem, Elgg

To create a menu item that is not a link, pass false for $href. Any undocumented properties set will be passed to the output/url view during rendering. E.g. to give a menu item a "target" attribute, set $item->target, or include a "target" key in the options array for factory().
Since: 1.8.0
Show file Open project: elgg/elgg Class Usage Examples

Protected Properties

Property Type Description
$confirm The string to display if link is clicked
$data Non-rendered data about the menu item
$href The menu url
$text The menu display string (HTML)
$title Tooltip

Public Methods

Method Description
__construct ( string $name, string $text, string $href ) \ElggMenuItem constructor
addChild ( ElggMenuItem $item ) : void Add a child menu item
addDeps ( string[] | string $modules ) : void Add required AMD modules
addItemClass ( mixed $class ) : void Add a li class
addLinkClass ( mixed $class ) : void Add a link class
factory ( array $options ) : ElggMenuItem Create an ElggMenuItem from an associative array. Required keys are name, text, and href.
getChildren ( ) : ElggMenuItem[] Get the children menu items
getConfirmText ( ) : string Get the confirm text
getContext ( ) : array Get an array of context strings
getData ( string $key ) : mixed Get stored data
getDeps ( ) : string[] Get required AMD modules
getHref ( ) : string Get the URL of the menu item
getItemClass ( ) : string Get the li classes as text
getLinkClass ( ) : string Get the anchor classes as text
getName ( ) : string Get the identifier of the menu item
getParent ( ) : ElggMenuItem Get the parent menu item
getParentName ( ) : string Get the parent identifier
getPriority ( ) : integer Get the priority of the menu item
getSection ( ) : string Get the section identifier
getSelected ( ) : boolean Get selected state
getText ( ) : string Get the display text of the menu item
getTooltip ( ) : string Get the tool tip text
getValues ( ) : array Get all the values for this menu item. Useful for rendering.
inContext ( string $context = '' ) : boolean Should this menu item be used given the current context
setChildren ( ElggMenuItem[] $children ) : void Set the menu item's children
setConfirmText ( string $text ) : void Set the confirm text shown when link is clicked
setContext ( array $contexts ) : void Set the contexts that this menu item is available for
setData ( mixed $key, mixed $value = null ) : void Set a data key/value pair or a set of key/value pairs
setDeps ( string[] | string $modules ) : void Set required AMD modules
setHref ( string $href ) : void Set the URL of the menu item
setItemClass ( mixed $class ) : void Set the li classes
setLinkClass ( mixed $class ) : void Set the anchor class
setName ( string $name ) : void Set the identifier of the menu item
setParent ( ElggMenuItem $parent ) : void Set the parent menu item
setParentName ( string $name ) : void Set the parent identifier
setPriority ( integer $priority ) : void Set the priority of the menu item
setSection ( string $section ) : void Set the section identifier
setSelected ( boolean $state = true ) : void Set the selected flag
setText ( string $text ) : void Set the display text of the menu item
setTooltip ( string $text ) : void Set the tool tip text
sortChildren ( string $sortFunction ) : void Sort the children

Protected Methods

Method Description
addClass ( array &$current, mixed $additional ) : void Add additional classes

Method Details

__construct() public method

\ElggMenuItem constructor
public __construct ( string $name, string $text, string $href )
$name string Identifier of the menu item
$text string Display text of the menu item (HTML)
$href string URL of the menu item (false if not a link)

addChild() public method

This is reserved for the \ElggMenuBuilder.
public addChild ( ElggMenuItem $item ) : void
$item ElggMenuItem A child menu item
return void

addClass() protected method

Add additional classes
protected addClass ( array &$current, mixed $additional ) : void
$current array The current array of classes
$additional mixed Additional classes (either array of string)
return void

addDeps() public method

Add required AMD modules
public addDeps ( string[] | string $modules ) : void
$modules string[] | string One or more required AMD modules
return void

addItemClass() public method

Add a li class
Since: 1.9.0
public addItemClass ( mixed $class ) : void
$class mixed An array of class names, or a single string class name.
return void

addLinkClass() public method

Add a link class
public addLinkClass ( mixed $class ) : void
$class mixed An array of class names, or a single string class name.
return void

getChildren() public method

This is reserved for the \ElggMenuBuilder.
public getChildren ( ) : ElggMenuItem[]
return ElggMenuItem[]

getConfirmText() public method

Get the confirm text
public getConfirmText ( ) : string
return string

getContext() public method

Get an array of context strings
public getContext ( ) : array
return array

getData() public method

Get stored data
public getData ( string $key ) : mixed
$key string The key for the requested key/value pair
return mixed

getDeps() public method

Get required AMD modules
public getDeps ( ) : string[]
return string[]

getHref() public method

Get the URL of the menu item
public getHref ( ) : string
return string

getItemClass() public method

Get the li classes as text
public getItemClass ( ) : string
return string

getLinkClass() public method

Get the anchor classes as text
public getLinkClass ( ) : string
return string

getName() public method

Get the identifier of the menu item
public getName ( ) : string
return string

getParent() public method

This is reserved for the \ElggMenuBuilder.
public getParent ( ) : ElggMenuItem
return ElggMenuItem or null

getParentName() public method

Get the parent identifier
public getParentName ( ) : string
return string

getPriority() public method

Get the priority of the menu item
public getPriority ( ) : integer
return integer

getSection() public method

Get the section identifier
public getSection ( ) : string
return string

getSelected() public method

Get selected state
public getSelected ( ) : boolean
return boolean

getText() public method

Get the display text of the menu item
public getText ( ) : string
return string The display text as HTML

getTooltip() public method

Get the tool tip text
public getTooltip ( ) : string
return string

getValues() public method

Get all the values for this menu item. Useful for rendering.
Since: 1.9.0
public getValues ( ) : array
return array

inContext() public method

Should this menu item be used given the current context
public inContext ( string $context = '' ) : boolean
$context string A context string (default is empty string for current context stack).
return boolean

setChildren() public method

This is reserved for the \ElggMenuBuilder.
public setChildren ( ElggMenuItem[] $children ) : void
$children ElggMenuItem[] Array of items
return void

setConfirmText() public method

Set the confirm text shown when link is clicked
public setConfirmText ( string $text ) : void
$text string The text to show
return void

setContext() public method

Set the contexts that this menu item is available for
public setContext ( array $contexts ) : void
$contexts array An array of context strings. Use 'all' to match all contexts.
return void

setData() public method

This method allows storage of arbitrary data with this menu item. The data can be used for sorting, custom rendering, or any other use.
public setData ( mixed $key, mixed $value = null ) : void
$key mixed String key or an associative array of key/value pairs
$value mixed The value if $key is a string
return void

setDeps() public method

Set required AMD modules
public setDeps ( string[] | string $modules ) : void
$modules string[] | string One or more required AMD modules
return void

setHref() public method

Set the URL of the menu item
public setHref ( string $href ) : void
$href string URL or false if not a link
return void

setItemClass() public method

Set the li classes
public setItemClass ( mixed $class ) : void
$class mixed An array of class names, or a single string class name.
return void

setLinkClass() public method

Set the anchor class
public setLinkClass ( mixed $class ) : void
$class mixed An array of class names, or a single string class name.
return void

setName() public method

Set the identifier of the menu item
public setName ( string $name ) : void
$name string Unique identifier
return void

setParent() public method

This is reserved for the \ElggMenuBuilder.
public setParent ( ElggMenuItem $parent ) : void
$parent ElggMenuItem The parent of this menu item
return void

setParentName() public method

Set the parent identifier
public setParentName ( string $name ) : void
$name string The identifier of the parent \ElggMenuItem
return void

setPriority() public method

Set the priority of the menu item
public setPriority ( integer $priority ) : void
$priority integer The smaller numbers mean higher priority (1 before 100)
return void

setSection() public method

Set the section identifier
public setSection ( string $section ) : void
$section string The identifier of the section
return void

setSelected() public method

Set the selected flag
public setSelected ( boolean $state = true ) : void
$state boolean Selected state (default is true)
return void

setText() public method

Set the display text of the menu item
public setText ( string $text ) : void
$text string The display text as HTML
return void

setTooltip() public method

Set the tool tip text
public setTooltip ( string $text ) : void
$text string The text of the tool tip
return void

sortChildren() public method

This is reserved for the \ElggMenuBuilder.
public sortChildren ( string $sortFunction ) : void
$sortFunction string A function that is passed to usort()
return void

Property Details

$confirm protected property

The string to display if link is clicked
protected $confirm

$data protected property

Non-rendered data about the menu item
protected $data

$href protected property

The menu url
protected $href

$text protected property

The menu display string (HTML)
protected $text

$title protected property

Tooltip
protected $title