Item
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.
Properties summary
Type | Property | Description | |
---|---|---|---|
protected | $badge | An optional badge displayed to the right of a menu item's label. | |
protected | $order | The order that a menu item appears in its hierarchy. | |
protected | $disabled | Tracks if a menu item is disabled. | |
protected | $icon | An optional icon displayed next to a menu item. | |
protected | $headingHtml | Raw HTML to be rendered in a menu body's heading area. | |
protected | $bodyHtml | Raw HTML to be rendered in a menu item's body area. | |
protected | $footerHtml | Raw HTML to be rendered in a menu item's footer area. |
Methods summary
Return Type | Method Name | Description | |
---|---|---|---|
string | getName() | Retrieve a menu item's name. | |
ItemInterface | setName(string $name) | Set a menu item's name. | |
string|null | getUri() | Retrieve a menu item's link target. | |
ItemInterface | setUri(string|null $uri) | Set a menu item's link target. | |
string | getLabel() | Retrieve a menu item's label. | |
ItemInterface | setLabel(string $label) | Set a menu item's label. | |
ItemInterface | addChild(Item|string $child, array $options = array()) | Add a child menu item. | |
ItemInterface|null | getChild(string $name) | Retrieve a menu item's child item by name. | |
ItemInterface | copy() | Make a copy of a menu item. | |
int | getLevel() | Retrieve a menu item's level in the menu tree. | |
ItemInterface | getRoot() | Retrieve the root menu item. | |
bool | isRoot() | Determine if a menu item is the root menu item. | |
ItemInterface|null | getParent() | Retrieve a menu item's parent item. | |
array | getChildren() | Retrieve a menu item's child items. | |
ItemInterface | setChildren(array $children) | Set a menu item's child items. | |
ItemInterface | removeChild(Item|string $name) | Remove a menu item's child item. | |
bool | hasChildren() | Determine if a menu item has child items. | |
ItemInterface | setBadge(string $badge) | Set a menu item's badge. | |
string|false | getBadge() | Retrieve a menu item's badge, or false if the badge isn't set. | |
bool | hasBadge() | Determine if a menu item has a badge. | |
Item | setOrder(int $order) | Set a menu item's sort order. | |
int | getOrder() | Retrieve a menu item's sort order. | |
Item | setClass(string $cssClassString) | Set a menu item's css class definitions. | |
string | getClass() | Retrieve a menu item's css class definitions. | |
Item | disable() | Set a menu item as disabled. | |
Item | enable() | Set a menu item as enabled. | |
bool | isDisabled() | Retrieve if a menu item is disabled. | |
array | getExtras() | Retrieve a key/value pair of menu item extras. | |
mixed | getExtra(string $name, mixed $default = null) | Retrieve a menu item extra by name. | |
ItemInterface | setExtras(array $extras) | Set a menu item's extras. | |
ItemInterface | setExtra(string $name, mixed $value) | Set a menu item extra. | |
bool | isFontAwesomeIcon(string $icon) | Determine if a string describes a Font Awesome icon. | |
bool | isGlyphicon(string $icon) | Determine if a string describes a Glyphicon. | |
Item | setIcon(string $icon) | Set the icon displayed next to a menu item. | |
string | getIcon() | Retrieve full CSS classes of the icon displayed next to a menu item. | |
bool | hasIcon() | Determine if a menu item has an icon. | |
bool | hasFontAwesomeIcon() | Determine if a menu item's icon is a Font Awesome icon. | |
bool | hasGlyphicon() | Determine if a menu item's icon is a Glyphicon. | |
string | getBodyHtml() | Retrieve a menu item's body HTML content. | |
Item | setBodyHtml(string $html) | Set a menu item's body HTML content. | |
bool | hasBodyHtml() | Determine if a menu item has body HTML. | |
string | getFooterHtml() | Retrieve a menu item's footer HTML content. | |
Item | setFooterHtml(string $html) | Set a menu item's footer HTML content. | |
bool | hasFooterHtml() | Determine if a menu item has footer HTML. | |
string | getHeadingHtml() | Retrieve a menu item's heading HTML content. | |
Item | setHeadingHtml(string $html) | Set a menu item's heading HTML content. | |
bool | hasHeadingHtml() | Determine if a menu item has heading HTML. | |
string | getId() | Build a menu item's CSS id. | |
static Item | sort(Item $menu, bool $sortChildren = true) | Sort a menu item's children by their sort order then alphabetically by name. | |
Item | swapOrder(string $swapOrder) | Swap the order of the current menu item with another menu item's order. | |
Item | moveUp() | Move a menu item up in sorting order. | |
Item | moveDown() | Move a menu item down in sorting order. | |
Item | moveToFront() | Move a menu item to the beginning of the sorting order. | |
Item | moveToBack() | Move a menu item to the end of the sorting order. |
Details
string
getName ()
Retrieve a menu item's name.
ItemInterface
setName (string $name)
Set a menu item's name.
string|null
getUri ()
Retrieve a menu item's link target.
ItemInterface
setUri (string|null $uri)
Set a menu item's link target.
string
getLabel ()
Retrieve a menu item's label.
If the label is undefined then retrieve the menu item's name.
ItemInterface
setLabel (string $label)
Set a menu item's label.
ItemInterface
addChild (Item|string $child, array $options = array())
Add a child menu item.
ItemInterface|null
getChild (string $name)
Retrieve a menu item's child item by name.
Return null if the child isn't found.
ItemInterface
copy ()
Make a copy of a menu item.
int
getLevel ()
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.
ItemInterface
getRoot ()
Retrieve the root menu item.
bool
isRoot ()
Determine if a menu item is the root menu item.
ItemInterface|null
getParent ()
Retrieve a menu item's parent item.
Return null if the menu item is the root menu item and has no parent item.
array
getChildren ()
Retrieve a menu item's child items.
ItemInterface
setChildren (array $children)
Set a menu item's child items.
ItemInterface
removeChild (Item|string $name)
Remove a menu item's child item.
bool
hasChildren ()
Determine if a menu item has child items.
ItemInterface
setBadge (string $badge)
Set a menu item's badge.
string|false
getBadge ()
Retrieve a menu item's badge, or false if the badge isn't set.
bool
hasBadge ()
Determine if a menu item has a badge.
Item
setOrder (int $order)
Set a menu item's sort order.
int
getOrder ()
Retrieve a menu item's sort order.
Item
setClass (string $cssClassString)
Set a menu item's css class definitions.
string
getClass ()
Retrieve a menu item's css class definitions.
Item
disable ()
Set a menu item as disabled.
Item
enable ()
Set a menu item as enabled.
bool
isDisabled ()
Retrieve if a menu item is disabled.
array
getExtras ()
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.
mixed
getExtra (string $name, mixed $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.
ItemInterface
setExtras (array $extras)
Set a menu item's extras.
Extras store miscellaneous data in a menu item and may or may not be used for menu display.
ItemInterface
setExtra (string $name, mixed $value)
Set a menu item extra.
Extras store miscellaneous data in a menu item and may or may not be used for menu display.
protected bool
isFontAwesomeIcon (string $icon)
Determine if a string describes a Font Awesome icon.
Font Awesome icon CSS classes begin with "fa-".
protected bool
isGlyphicon (string $icon)
Determine if a string describes a Glyphicon.
Glyphicon icon CSS classes begin with "glyphicon-".
Item
setIcon (string $icon)
Set the icon displayed next to a menu item.
string
getIcon ()
Retrieve full CSS classes of the icon displayed next to a menu item.
bool
hasIcon ()
Determine if a menu item has an icon.
bool
hasFontAwesomeIcon ()
Determine if a menu item's icon is a Font Awesome icon.
bool
hasGlyphicon ()
Determine if a menu item's icon is a Glyphicon.
string
getBodyHtml ()
Retrieve a menu item's body HTML content.
Item
setBodyHtml (string $html)
Set a menu item's body HTML content.
bool
hasBodyHtml ()
Determine if a menu item has body HTML.
string
getFooterHtml ()
Retrieve a menu item's footer HTML content.
Item
setFooterHtml (string $html)
Set a menu item's footer HTML content.
bool
hasFooterHtml ()
Determine if a menu item has footer HTML.
string
getHeadingHtml ()
Retrieve a menu item's heading HTML content.
Item
setHeadingHtml (string $html)
Set a menu item's heading HTML content.
bool
hasHeadingHtml ()
Determine if a menu item has heading HTML.
string
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
static Item
sort (Item $menu, bool $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.
protected Item
swapOrder (string $swapOrder)
Swap the order of the current menu item with another menu item's order.
Item
moveUp ()
Move a menu item up in sorting order.
Item
moveDown ()
Move a menu item down in sorting order.
Item
moveToFront ()
Move a menu item to the beginning of the sorting order.
Item
moveToBack ()
Move a menu item to the end of the sorting order.