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.

class Item extends MenuItem

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.

Return Value

string

ItemInterface setName (string $name)

Set a menu item's name.

Parameters

string $name

Return Value

ItemInterface

Exceptions

InvalidArgumentException if the name is already in use by one of the menu item's siblings.

string|null getUri ()

Retrieve a menu item's link target.

Return Value

string|null

ItemInterface setUri (string|null $uri)

Set a menu item's link target.

Parameters

string|null $uri

Return Value

ItemInterface

string getLabel ()

Retrieve a menu item's label.

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

Return Value

string

ItemInterface setLabel (string $label)

Set a menu item's label.

Parameters

string $label

Return Value

ItemInterface

ItemInterface addChild (Item|string $child, array $options = array())

Add a child menu item.

Parameters

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.

Return Value

ItemInterface

Exceptions

InvalidArgumentException if $child already has a parent menu item.

ItemInterface|null getChild (string $name)

Retrieve a menu item's child item by name.

Return null if the child isn't found.

Parameters

string $name

Return Value

ItemInterface|null

ItemInterface copy ()

Make a copy of a menu item.

Return Value

ItemInterface

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.

Return Value

int

ItemInterface getRoot ()

Retrieve the root menu item.

Return Value

ItemInterface

bool isRoot ()

Determine if a menu item is the root menu item.

Return Value

bool

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.

Return Value

ItemInterface|null

array getChildren ()

Retrieve a menu item's child items.

Return Value

array

ItemInterface setChildren (array $children)

Set a menu item's child items.

Parameters

array $children

Return Value

ItemInterface

ItemInterface removeChild (Item|string $name)

Remove a menu item's child item.

Parameters

Item|string $name

Return Value

ItemInterface

bool hasChildren ()

Determine if a menu item has child items.

Return Value

bool

ItemInterface setBadge (string $badge)

Set a menu item's badge.

Parameters

string $badge

Return Value

ItemInterface

string|false getBadge ()

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

Return Value

string|false

bool hasBadge ()

Determine if a menu item has a badge.

Return Value

bool

Item setOrder (int $order)

Set a menu item's sort order.

Parameters

int $order

Return Value

Item

int getOrder ()

Retrieve a menu item's sort order.

Return Value

int

Item setClass (string $cssClassString)

Set a menu item's css class definitions.

Parameters

string $cssClassString

Return Value

Item

string getClass ()

Retrieve a menu item's css class definitions.

Return Value

string

Item disable ()

Set a menu item as disabled.

Return Value

Item

Item enable ()

Set a menu item as enabled.

Return Value

Item

bool isDisabled ()

Retrieve if a menu item is disabled.

Return Value

bool

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.

Return Value

array

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.

Parameters

string $name
mixed $default

Return Value

mixed

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.

Parameters

array $extras

Return Value

ItemInterface

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.

Parameters

string $name
mixed $value

Return Value

ItemInterface

protected bool isFontAwesomeIcon (string $icon)

Determine if a string describes a Font Awesome icon.

Font Awesome icon CSS classes begin with "fa-".

Parameters

string $icon

Return Value

bool

protected bool isGlyphicon (string $icon)

Determine if a string describes a Glyphicon.

Glyphicon icon CSS classes begin with "glyphicon-".

Parameters

string $icon

Return Value

bool

Item setIcon (string $icon)

Set the icon displayed next to a menu item.

Parameters

string $icon

Return Value

Item

Exceptions

Exception if an icon is provided and is not a Font Awesome or Glyphicon.

string getIcon ()

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

Return Value

string

bool hasIcon ()

Determine if a menu item has an icon.

Return Value

bool

bool hasFontAwesomeIcon ()

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

Return Value

bool

bool hasGlyphicon ()

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

Return Value

bool

string getBodyHtml ()

Retrieve a menu item's body HTML content.

Return Value

string

Item setBodyHtml (string $html)

Set a menu item's body HTML content.

Parameters

string $html

Return Value

Item

bool hasBodyHtml ()

Determine if a menu item has body HTML.

Return Value

bool

string getFooterHtml ()

Retrieve a menu item's footer HTML content.

Return Value

string

Item setFooterHtml (string $html)

Set a menu item's footer HTML content.

Parameters

string $html

Return Value

Item

bool hasFooterHtml ()

Determine if a menu item has footer HTML.

Return Value

bool

string getHeadingHtml ()

Retrieve a menu item's heading HTML content.

Return Value

string

Item setHeadingHtml (string $html)

Set a menu item's heading HTML content.

Parameters

string $html

Return Value

Item

bool hasHeadingHtml ()

Determine if a menu item has heading HTML.

Return Value

bool

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

Return Value

string

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.

Parameters

Item $menu
bool $sortChildren

Return Value

Item

protected Item swapOrder (string $swapOrder)

Swap the order of the current menu item with another menu item's order.

Parameters

string $swapOrder "up" or "down"

Return Value

Item

Item moveUp ()

Move a menu item up in sorting order.

Return Value

Item

Item moveDown ()

Move a menu item down in sorting order.

Return Value

Item

Item moveToFront ()

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

Return Value

Item

Item moveToBack ()

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

Return Value

Item