Elgg  Version master
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ElggMenuItem Class Reference

Elgg Menu Item. More...

Inheritance diagram for ElggMenuItem:
Elgg\Collections\CollectionItemInterface

Public Member Functions

 __construct ($name, $text, $href)
 constructor More...
 
 setData ($key, $value=null)
 Set a data key/value pair or a set of key/value pairs. More...
 
 getData ($key)
 Get stored data. More...
 
 setName ($name)
 Set the identifier of the menu item. More...
 
 getName ()
 Get the identifier of the menu item. More...
 
 setText ($text)
 Set the display text of the menu item. More...
 
 getText ()
 Get the display text of the menu item. More...
 
 setHref ($href)
 Set the URL of the menu item. More...
 
 getHref ()
 Get the URL of the menu item. More...
 
 setContext ($contexts)
 Set the contexts that this menu item is available for. More...
 
 getContext ()
 Get an array of context strings. More...
 
 inContext ($context= '')
 Should this menu item be used given the current context. More...
 
 setSelected ($state=true)
 Set the selected flag. More...
 
 getSelected ()
 Get selected state. More...
 
 setTooltip ($text)
 Set the tool tip text. More...
 
 getTooltip ()
 Get the tool tip text. More...
 
 setConfirmText ($text)
 Set the confirm text shown when link is clicked. More...
 
 getConfirmText ()
 Get the confirm text. More...
 
 setLinkClass ($class)
 Set the anchor class. More...
 
 getLinkClass ()
 Get the anchor classes as text. More...
 
 addLinkClass ($class)
 Add a link class. More...
 
 setDeps ($modules)
 Set required AMD modules. More...
 
 getDeps ()
 Get required AMD modules. More...
 
 addDeps ($modules)
 Add required AMD modules. More...
 
 setChildMenuOptions (array $options=[])
 Set child menu options for a parent item. More...
 
 getChildMenuOptions ()
 Returns child menu options for parent items. More...
 
 setItemClass ($class)
 Set the li classes. More...
 
 getItemClass ()
 Get the li classes as text. More...
 
 addItemClass ($class)
 Add a li class. More...
 
 setPriority (int $priority)
 Set the priority of the menu item. More...
 
 getPriority ()
 Get the priority of the menu item. More...
 
 setSection ($section)
 Set the section identifier. More...
 
 getSection ()
 Get the section identifier. More...
 
 setParentName ($name)
 Set the parent identifier. More...
 
 getParentName ()
 Get the parent identifier. More...
 
 setParent ($parent)
 Set the parent menu item. More...
 
 getParent ()
 Get the parent menu item. More...
 
 addChild ($item)
 Add a child menu item. More...
 
 setChildren ($children)
 Set the menu item's children. More...
 
 getChildren ()
 Get the children menu items. More...
 
 sortChildren ($sortFunction)
 Sort the children. More...
 
 getValues ()
 Get all the values for this menu item. More...
 
 getID ()
 Get unique item identifier within a collection. More...
 
 setItemContentsView (string $view_name)
 Set the item contents view. More...
 
 getItemContentsView ()
 Get the item contents view. More...
 
 hasItemContentsView ()
 Check if the menu items has a contents view set. More...
 

Static Public Member Functions

static factory (array $options)
 Create an ElggMenuItem from an associative array. More...
 

Protected Member Functions

 addClass (array &$current, $additional)
 Add additional classes. More...
 

Protected Attributes

 $data
 
 $text
 
 $href = null
 
 $title = false
 
 $confirm = ''
 

Detailed Description

Elgg Menu Item.

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

Definition at line 13 of file ElggMenuItem.php.

Constructor & Destructor Documentation

ElggMenuItem::__construct (   $name,
  $text,
  $href 
)

constructor

Parameters
string$nameIdentifier of the menu item
string$textDisplay text of the menu item (HTML)
string$hrefURL of the menu item (false if not a link)

Definition at line 90 of file ElggMenuItem.php.

Member Function Documentation

ElggMenuItem::addChild (   $item)

Add a child menu item.

Parameters
\ElggMenuItem$itemA child menu item
Returns
void

Definition at line 613 of file ElggMenuItem.php.

ElggMenuItem::addClass ( array &  $current,
  $additional 
)
protected

Add additional classes.

Parameters
array$currentThe current array of classes
mixed$additionalAdditional classes (either array of string)
Returns
void

Definition at line 517 of file ElggMenuItem.php.

ElggMenuItem::addDeps (   $modules)

Add required AMD modules.

Parameters
string[]|string$modules One or more required AMD modules
Returns
void

Definition at line 444 of file ElggMenuItem.php.

ElggMenuItem::addItemClass (   $class)

Add a li class.

Parameters
mixed$classAn array of class names, or a single string class name.
Returns
void
Since
1.9.0

Definition at line 506 of file ElggMenuItem.php.

ElggMenuItem::addLinkClass (   $class)

Add a link class.

Parameters
mixed$classAn array of class names, or a single string class name.
Returns
void

Definition at line 412 of file ElggMenuItem.php.

static ElggMenuItem::factory ( array  $options)
static

Create an ElggMenuItem from an associative array.

Required keys are name, text, and href.

Commonly used params: name => STR Menu item identifier (required) text => STR Menu item display text as HTML (required) href => STR Menu item URL (required) false = do not create a link. null = current URL. "" = current URL. "/" = site home page.

Warning
If href is false, the tag will not appear, so the link_class will not apply. If you put tags in manually through the 'text' option the default CSS selector .elgg-menu-$menu > li > a may affect formatting. Wrap in a if it does.)

section => STR Menu section identifier link_class => STR A class or classes for the tag item_class => STR A class or classes for the tag parent_name => STR Identifier of the parent menu item contexts => ARR Page context strings title => STR Menu item tooltip selected => BOOL Is this menu item currently selected? confirm => STR If set, the link will be drawn with the output/confirmlink view instead of output/url. deps => ARR AMD modules required by this menu item child_menu => ARR Options for the child menu data => ARR Custom attributes stored in the menu item.

Parameters
array$optionsOption array of key value pairs
Returns
Exceptions

Definition at line 135 of file ElggMenuItem.php.

ElggMenuItem::getChildMenuOptions ( )

Returns child menu options for parent items.

Returns
array

Definition at line 464 of file ElggMenuItem.php.

ElggMenuItem::getChildren ( )

Get the children menu items.

Returns
ElggMenuItem[]

Definition at line 636 of file ElggMenuItem.php.

ElggMenuItem::getConfirmText ( )

Get the confirm text.

Returns
string

Definition at line 379 of file ElggMenuItem.php.

ElggMenuItem::getContext ( )

Get an array of context strings.

Returns
array

Definition at line 293 of file ElggMenuItem.php.

ElggMenuItem::getData (   $key)

Get stored data.

Parameters
string$keyThe key for the requested key/value pair
Returns
mixed

Definition at line 210 of file ElggMenuItem.php.

ElggMenuItem::getDeps ( )

Get required AMD modules.

Returns
string[]

Definition at line 431 of file ElggMenuItem.php.

ElggMenuItem::getHref ( )

Get the URL of the menu item.

Returns
string|false|null

Definition at line 271 of file ElggMenuItem.php.

ElggMenuItem::getID ( )

Get unique item identifier within a collection.

Returns
string|int

Implements Elgg\Collections\CollectionItemInterface.

Definition at line 674 of file ElggMenuItem.php.

ElggMenuItem::getItemClass ( )

Get the li classes as text.

Returns
string

Definition at line 487 of file ElggMenuItem.php.

ElggMenuItem::getItemContentsView ( )

Get the item contents view.

Returns
string|null
Since
4.2

Definition at line 696 of file ElggMenuItem.php.

ElggMenuItem::getLinkClass ( )

Get the anchor classes as text.

Returns
string

Definition at line 402 of file ElggMenuItem.php.

ElggMenuItem::getName ( )

Get the identifier of the menu item.

Returns
string

Definition at line 233 of file ElggMenuItem.php.

ElggMenuItem::getParent ( )

Get the parent menu item.

Returns
or null

Definition at line 601 of file ElggMenuItem.php.

ElggMenuItem::getParentName ( )

Get the parent identifier.

Returns
string

Definition at line 578 of file ElggMenuItem.php.

ElggMenuItem::getPriority ( )

Get the priority of the menu item.

Returns
int

Implements Elgg\Collections\CollectionItemInterface.

Definition at line 540 of file ElggMenuItem.php.

ElggMenuItem::getSection ( )

Get the section identifier.

Returns
string

Definition at line 559 of file ElggMenuItem.php.

ElggMenuItem::getSelected ( )

Get selected state.

Returns
bool

Definition at line 337 of file ElggMenuItem.php.

ElggMenuItem::getText ( )

Get the display text of the menu item.

Returns
string The display text as HTML

Definition at line 252 of file ElggMenuItem.php.

ElggMenuItem::getTooltip ( )

Get the tool tip text.

Returns
string

Definition at line 360 of file ElggMenuItem.php.

ElggMenuItem::getValues ( )

Get all the values for this menu item.

Useful for rendering.

Returns
array
Since
1.9.0

Definition at line 663 of file ElggMenuItem.php.

ElggMenuItem::hasItemContentsView ( )

Check if the menu items has a contents view set.

Returns
bool
Since
4.2

Definition at line 706 of file ElggMenuItem.php.

ElggMenuItem::inContext (   $context = '')

Should this menu item be used given the current context.

Parameters
string$contextA context string (default is empty string for current context stack).
Returns
bool

Definition at line 304 of file ElggMenuItem.php.

ElggMenuItem::setChildMenuOptions ( array  $options = [])

Set child menu options for a parent item.

Parameters
array$optionsOptions
Returns
void

Definition at line 455 of file ElggMenuItem.php.

ElggMenuItem::setChildren (   $children)

Set the menu item's children.

Parameters
ElggMenuItem[]$children Array of items
Returns
void

Definition at line 625 of file ElggMenuItem.php.

ElggMenuItem::setConfirmText (   $text)

Set the confirm text shown when link is clicked.

Parameters
string$textThe text to show
Returns
void

Definition at line 370 of file ElggMenuItem.php.

ElggMenuItem::setContext (   $contexts)

Set the contexts that this menu item is available for.

Parameters
array$contextsAn array of context strings. Use 'all' to match all contexts.
Returns
void

Definition at line 281 of file ElggMenuItem.php.

ElggMenuItem::setData (   $key,
  $value = null 
)

Set a data key/value pair or a set of key/value pairs.

This method allows storage of arbitrary data with this menu item. The data can be used for sorting, custom rendering, or any other use.

Parameters
mixed$keyString key or an associative array of key/value pairs
mixed$valueThe value if $key is a string
Returns
void

Definition at line 196 of file ElggMenuItem.php.

ElggMenuItem::setDeps (   $modules)

Set required AMD modules.

Parameters
string[]|string$modules One or more required AMD modules
Returns
void

Definition at line 422 of file ElggMenuItem.php.

ElggMenuItem::setHref (   $href)

Set the URL of the menu item.

Parameters
string$hrefURL or false if not a link
Returns
void

Definition at line 262 of file ElggMenuItem.php.

ElggMenuItem::setItemClass (   $class)

Set the li classes.

Parameters
mixed$classAn array of class names, or a single string class name.
Returns
void

Definition at line 474 of file ElggMenuItem.php.

ElggMenuItem::setItemContentsView ( string  $view_name)

Set the item contents view.

Parameters
string$view_namethe name of the output view
Returns
void
Since
4.2

Definition at line 686 of file ElggMenuItem.php.

ElggMenuItem::setLinkClass (   $class)

Set the anchor class.

Parameters
mixed$classAn array of class names, or a single string class name.
Returns
void

Definition at line 389 of file ElggMenuItem.php.

ElggMenuItem::setName (   $name)

Set the identifier of the menu item.

Parameters
string$nameUnique identifier
Returns
void

Definition at line 224 of file ElggMenuItem.php.

ElggMenuItem::setParent (   $parent)

Set the parent menu item.

Parameters
\ElggMenuItem$parentThe parent of this menu item
Returns
void

Definition at line 590 of file ElggMenuItem.php.

ElggMenuItem::setParentName (   $name)

Set the parent identifier.

Parameters
string$nameThe identifier of the parent
Returns
void

Definition at line 569 of file ElggMenuItem.php.

ElggMenuItem::setPriority ( int  $priority)

Set the priority of the menu item.

Parameters
int$priorityThe smaller numbers mean higher priority (1 before 100)
Returns
void

Definition at line 531 of file ElggMenuItem.php.

ElggMenuItem::setSection (   $section)

Set the section identifier.

Parameters
string$sectionThe identifier of the section
Returns
void

Definition at line 550 of file ElggMenuItem.php.

ElggMenuItem::setSelected (   $state = true)

Set the selected flag.

Parameters
bool$stateSelected state (default is true)
Returns
void

Definition at line 328 of file ElggMenuItem.php.

ElggMenuItem::setText (   $text)

Set the display text of the menu item.

Parameters
string$textThe display text as HTML
Returns
void

Definition at line 243 of file ElggMenuItem.php.

ElggMenuItem::setTooltip (   $text)

Set the tool tip text.

Parameters
string$textThe text of the tool tip
Returns
void

Definition at line 351 of file ElggMenuItem.php.

ElggMenuItem::sortChildren (   $sortFunction)

Sort the children.

Parameters
callable$sortFunctionA function that is passed to usort()
Returns
void

Definition at line 649 of file ElggMenuItem.php.

Member Data Documentation

ElggMenuItem::$confirm = ''
protected

Definition at line 80 of file ElggMenuItem.php.

ElggMenuItem::$data
protected
Initial value:
= [
'name' => ''

Definition at line 18 of file ElggMenuItem.php.

ElggMenuItem::$href = null
protected

Definition at line 70 of file ElggMenuItem.php.

ElggMenuItem::$text
protected

Definition at line 65 of file ElggMenuItem.php.

ElggMenuItem::$title = false
protected

Definition at line 75 of file ElggMenuItem.php.


The documentation for this class was generated from the following file: