Class · extends MenuItem
An item in one of WHMCS's client area menus.
Menu item objects are the core building block to all programmable client area menus in WHMCS. They power dynamic navigation bars, sidebars, the client area home page's panels, and other UI elements. Individual menu items contain all of the components necessary to render it on a page including display labels, links, icons, and certain HTML elements.
Menu items are arranged in a tree structure. A menu item can have many child items and one parent item. The only item with no parent is the root menu item at the top of the tree. The root menu item has access to every child item in the menu tree.
public function getName(): stringRetrieve a menu item's name.
Returns string
public function setName(string $name): ItemInterfaceSet a menu item's name.
Parameters
| Type | Name | Description |
|---|---|---|
string | $name |
Returns Item
public function getUri(): ?stringRetrieve a menu item's link target.
Returns string
public function setUri(?string $uri): ItemInterfaceSet a menu item's link target.
Parameters
| Type | Name | Description |
|---|---|---|
string|null | $uri |
Returns Item
public function getLabel(): stringRetrieve a menu item's label.
If the label is undefined then retrieve the menu item's name.
Returns string
public function setLabel(?string $label): ItemInterfaceSet a menu item's label.
Parameters
| Type | Name | Description |
|---|---|---|
?string | $label |
Returns Item
public function addChild($child, array $options = array()): ItemInterfaceAdd a child menu item.
Parameters
| Type | Name | Description |
|---|---|---|
Item|string | $child | either a menu item or the name of the child item. |
array | $options | the child item's options if $child is a string. |
Returns Item
public function getChild(string $name): ?ItemInterfaceRetrieve a menu item's child item by name.
Return null if the child isn't found.
Parameters
| Type | Name | Description |
|---|---|---|
string | $name |
Returns Item\|null
public function copy(): ItemInterfaceMake a copy of a menu item.
Returns Item
public function getLevel(): intRetrieve a menu item's level in the menu tree.
The root menu item has level 0, its children have level 1, their children level 2, and so on.
Returns int
public function getRoot(): ItemInterfaceRetrieve the root menu item.
Returns Item
public function isRoot(): boolDetermine if a menu item is the root menu item.
Returns bool
public function getParent(): ?ItemInterfaceRetrieve a menu item's parent item.
Return null if the menu item is the root menu item and has no parent item.
Returns Item\|null
public function getChildren(): arrayRetrieve a menu item's child items.
Returns Item[]
public function setChildren(array $children): ItemInterfaceSet a menu item's child items.
Parameters
| Type | Name | Description |
|---|---|---|
Item[] | $children |
Returns Item
public function removeChild($name): ItemInterfaceRemove a menu item's child item.
Parameters
| Type | Name | Description |
|---|---|---|
Item|string | $name |
Returns Item
public function hasChildren(): boolDetermine if a menu item has child items.
Returns bool
public function setBadge($badge): ItemInterfaceSet a menu item's badge.
Parameters
| Type | Name | Description |
|---|---|---|
string | $badge |
Returns Item
public function getBadge()Retrieve a menu item's badge, or false if the badge isn't set.
Returns string\|false
public function hasBadge()Determine if a menu item has a badge.
Returns bool
public function setOrder($order)Set a menu item's sort order.
Parameters
| Type | Name | Description |
|---|---|---|
int | $order |
Returns Item
public function getOrder()Retrieve a menu item's sort order.
Returns int
public function setClass($cssClassString)Set a menu item's css class definitions.
Parameters
| Type | Name | Description |
|---|---|---|
string | $cssClassString |
Returns Item
public function getClass()Retrieve a menu item's css class definitions.
Returns string
public function disable()Set a menu item as disabled.
Returns Item
public function enable()Set a menu item as enabled.
Returns Item
public function isDisabled()Retrieve if a menu item is disabled.
Returns bool
public function getExtras(): arrayRetrieve a key/value pair of menu item extras.
Extras store miscellaneous data in a menu item and may or may not be used for menu display.
Returns array
public function getExtra(string $name, $default = null)Retrieve a menu item extra by name.
Extras store miscellaneous data in a menu item and may or may not be used for menu display.
Parameters
| Type | Name | Description |
|---|---|---|
string | $name | |
mixed | $default |
Returns mixed
public function setExtras(array $extras): ItemInterfaceSet a menu item's extras.
Extras store miscellaneous data in a menu item and may or may not be used for menu display.
Parameters
| Type | Name | Description |
|---|---|---|
array | $extras |
Returns Item
public function setExtra(string $name, $value): ItemInterfaceSet a menu item extra.
Extras store miscellaneous data in a menu item and may or may not be used for menu display.
Parameters
| Type | Name | Description |
|---|---|---|
string | $name | |
mixed | $value |
Returns Item
public function setIcon($icon)Set the icon displayed next to a menu item.
Parameters
| Type | Name | Description |
|---|---|---|
string | $icon |
Returns Item
public function getIcon()Retrieve full CSS classes of the icon displayed next to a menu item.
Returns string
public function hasIcon()Determine if a menu item has an icon.
Returns bool
public function hasFontAwesomeIcon()Determine if a menu item's icon is a Font Awesome icon.
Returns bool
public function hasGlyphicon()Determine if a menu item's icon is a Glyphicon.
Returns bool
public function getBodyHtml()Retrieve a menu item's body HTML content.
Returns string
public function setBodyHtml($html)Set a menu item's body HTML content.
Parameters
| Type | Name | Description |
|---|---|---|
string | $html |
Returns Item
public function hasBodyHtml()Determine if a menu item has body HTML.
Returns bool
public function getFooterHtml()Retrieve a menu item's footer HTML content.
Returns string
public function setFooterHtml($html)Set a menu item's footer HTML content.
Parameters
| Type | Name | Description |
|---|---|---|
string | $html |
Returns Item
public function hasFooterHtml()Determine if a menu item has footer HTML.
Returns bool
public function getHeadingHtml()Retrieve a menu item's heading HTML content.
Returns string
public function setHeadingHtml($html)Set a menu item's heading HTML content.
Parameters
| Type | Name | Description |
|---|---|---|
string | $html |
Returns Item
public function hasHeadingHtml()Determine if a menu item has heading HTML.
Returns bool
public function getId()Build a menu item's CSS id.
A Menu item's CSS id is a hyphen delineated string of the snake_case representations of a menu item's name followed by its parent item's name until the menu root.
For example a menu with the structure:
- My Menu ** My Submenu
has the CSS ids:
- My_Menu ** My_Menu-My_Submenu
Returns string
public static function sort(Item $menu, $sortChildren = true)Sort a menu item's children by their sort order then alphabetically by name.
A menu item's sorting order is defined in its "order" parameter, and is sorted in ascending order. If two menu items sort orders are the same then order them alphabetically by name.
Parameters
| Type | Name | Description |
|---|---|---|
Item | $menu | |
bool | $sortChildren |
Returns Item
public function moveUp()Move a menu item up in sorting order.
Returns Item
public function moveDown()Move a menu item down in sorting order.
Returns Item
public function moveToFront()Move a menu item to the beginning of the sorting order.
Returns Item
public function moveToBack()Move a menu item to the end of the sorting order.
Returns Item