Skip to content
Last updated

WHMCS\View\Menu\Item

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.

Methods

getName

public function getName(): string

Retrieve a menu item's name.

Returns string

setName

public function setName(string $name): ItemInterface

Set a menu item's name.

Parameters

TypeNameDescription
string$name

Returns Item

getUri

public function getUri(): ?string

Retrieve a menu item's link target.

Returns string

setUri

public function setUri(?string $uri): ItemInterface

Set a menu item's link target.

Parameters

TypeNameDescription
string|null$uri

Returns Item

getLabel

public function getLabel(): string

Retrieve a menu item's label.

If the label is undefined then retrieve the menu item's name.

Returns string

setLabel

public function setLabel(?string $label): ItemInterface

Set a menu item's label.

Parameters

TypeNameDescription
?string$label

Returns Item

addChild

public function addChild($child, array $options = array()): ItemInterface

Add a child menu item.

Parameters

TypeNameDescription
Item|string$childeither a menu item or the name of the child item.
array$optionsthe child item's options if $child is a string.

Returns Item

getChild

public function getChild(string $name): ?ItemInterface

Retrieve a menu item's child item by name.

Return null if the child isn't found.

Parameters

TypeNameDescription
string$name

Returns Item\|null

copy

public function copy(): ItemInterface

Make a copy of a menu item.

Returns Item

getLevel

public function getLevel(): int

Retrieve 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

getRoot

public function getRoot(): ItemInterface

Retrieve the root menu item.

Returns Item

isRoot

public function isRoot(): bool

Determine if a menu item is the root menu item.

Returns bool

getParent

public function getParent(): ?ItemInterface

Retrieve 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

getChildren

public function getChildren(): array

Retrieve a menu item's child items.

Returns Item[]

setChildren

public function setChildren(array $children): ItemInterface

Set a menu item's child items.

Parameters

TypeNameDescription
Item[]$children

Returns Item

removeChild

public function removeChild($name): ItemInterface

Remove a menu item's child item.

Parameters

TypeNameDescription
Item|string$name

Returns Item

hasChildren

public function hasChildren(): bool

Determine if a menu item has child items.

Returns bool

setBadge

public function setBadge($badge): ItemInterface

Set a menu item's badge.

Parameters

TypeNameDescription
string$badge

Returns Item

getBadge

public function getBadge()

Retrieve a menu item's badge, or false if the badge isn't set.

Returns string\|false

hasBadge

public function hasBadge()

Determine if a menu item has a badge.

Returns bool

setOrder

public function setOrder($order)

Set a menu item's sort order.

Parameters

TypeNameDescription
int$order

Returns Item

getOrder

public function getOrder()

Retrieve a menu item's sort order.

Returns int

setClass

public function setClass($cssClassString)

Set a menu item's css class definitions.

Parameters

TypeNameDescription
string$cssClassString

Returns Item

getClass

public function getClass()

Retrieve a menu item's css class definitions.

Returns string

disable

public function disable()

Set a menu item as disabled.

Returns Item

enable

public function enable()

Set a menu item as enabled.

Returns Item

isDisabled

public function isDisabled()

Retrieve if a menu item is disabled.

Returns bool

getExtras

public function getExtras(): array

Retrieve 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

getExtra

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

TypeNameDescription
string$name
mixed$default

Returns mixed

setExtras

public function setExtras(array $extras): ItemInterface

Set a menu item's extras.

Extras store miscellaneous data in a menu item and may or may not be used for menu display.

Parameters

TypeNameDescription
array$extras

Returns Item

setExtra

public function setExtra(string $name, $value): ItemInterface

Set a menu item extra.

Extras store miscellaneous data in a menu item and may or may not be used for menu display.

Parameters

TypeNameDescription
string$name
mixed$value

Returns Item

setIcon

public function setIcon($icon)

Set the icon displayed next to a menu item.

Parameters

TypeNameDescription
string$icon

Returns Item

getIcon

public function getIcon()

Retrieve full CSS classes of the icon displayed next to a menu item.

Returns string

hasIcon

public function hasIcon()

Determine if a menu item has an icon.

Returns bool

hasFontAwesomeIcon

public function hasFontAwesomeIcon()

Determine if a menu item's icon is a Font Awesome icon.

Returns bool

hasGlyphicon

public function hasGlyphicon()

Determine if a menu item's icon is a Glyphicon.

Returns bool

getBodyHtml

public function getBodyHtml()

Retrieve a menu item's body HTML content.

Returns string

setBodyHtml

public function setBodyHtml($html)

Set a menu item's body HTML content.

Parameters

TypeNameDescription
string$html

Returns Item

hasBodyHtml

public function hasBodyHtml()

Determine if a menu item has body HTML.

Returns bool

getFooterHtml

public function getFooterHtml()

Retrieve a menu item's footer HTML content.

Returns string

setFooterHtml

public function setFooterHtml($html)

Set a menu item's footer HTML content.

Parameters

TypeNameDescription
string$html

Returns Item

hasFooterHtml

public function hasFooterHtml()

Determine if a menu item has footer HTML.

Returns bool

getHeadingHtml

public function getHeadingHtml()

Retrieve a menu item's heading HTML content.

Returns string

setHeadingHtml

public function setHeadingHtml($html)

Set a menu item's heading HTML content.

Parameters

TypeNameDescription
string$html

Returns Item

hasHeadingHtml

public function hasHeadingHtml()

Determine if a menu item has heading HTML.

Returns bool

getId

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

sort

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

TypeNameDescription
Item$menu
bool$sortChildren

Returns Item

moveUp

public function moveUp()

Move a menu item up in sorting order.

Returns Item

moveDown

public function moveDown()

Move a menu item down in sorting order.

Returns Item

moveToFront

public function moveToFront()

Move a menu item to the beginning of the sorting order.

Returns Item

moveToBack

public function moveToBack()

Move a menu item to the end of the sorting order.

Returns Item