# 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

```php
public function getName(): string
```

Retrieve a menu item's name.

**Returns** `string`

### setName

```php
public function setName(string $name): ItemInterface
```

Set a menu item's name.

**Parameters**

| Type | Name | Description |
|  --- | --- | --- |
| `string` | `$name` |  |


**Returns** `Item`

### getUri

```php
public function getUri(): ?string
```

Retrieve a menu item's link target.

**Returns** `string`

### setUri

```php
public function setUri(?string $uri): ItemInterface
```

Set a menu item's link target.

**Parameters**

| Type | Name | Description |
|  --- | --- | --- |
| `string|null` | `$uri` |  |


**Returns** `Item`

### getLabel

```php
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

```php
public function setLabel(?string $label): ItemInterface
```

Set a menu item's label.

**Parameters**

| Type | Name | Description |
|  --- | --- | --- |
| `?string` | `$label` |  |


**Returns** `Item`

### addChild

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

Add 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`

### getChild

```php
public function getChild(string $name): ?ItemInterface
```

Retrieve 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`

### copy

```php
public function copy(): ItemInterface
```

Make a copy of a menu item.

**Returns** `Item`

### getLevel

```php
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

```php
public function getRoot(): ItemInterface
```

Retrieve the root menu item.

**Returns** `Item`

### isRoot

```php
public function isRoot(): bool
```

Determine if a menu item is the root menu item.

**Returns** `bool`

### getParent

```php
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

```php
public function getChildren(): array
```

Retrieve a menu item's child items.

**Returns** `Item[]`

### setChildren

```php
public function setChildren(array $children): ItemInterface
```

Set a menu item's child items.

**Parameters**

| Type | Name | Description |
|  --- | --- | --- |
| `Item[]` | `$children` |  |


**Returns** `Item`

### removeChild

```php
public function removeChild($name): ItemInterface
```

Remove a menu item's child item.

**Parameters**

| Type | Name | Description |
|  --- | --- | --- |
| `Item|string` | `$name` |  |


**Returns** `Item`

### hasChildren

```php
public function hasChildren(): bool
```

Determine if a menu item has child items.

**Returns** `bool`

### setBadge

```php
public function setBadge($badge): ItemInterface
```

Set a menu item's badge.

**Parameters**

| Type | Name | Description |
|  --- | --- | --- |
| `string` | `$badge` |  |


**Returns** `Item`

### getBadge

```php
public function getBadge()
```

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

**Returns** `string\|false`

### hasBadge

```php
public function hasBadge()
```

Determine if a menu item has a badge.

**Returns** `bool`

### setOrder

```php
public function setOrder($order)
```

Set a menu item's sort order.

**Parameters**

| Type | Name | Description |
|  --- | --- | --- |
| `int` | `$order` |  |


**Returns** `Item`

### getOrder

```php
public function getOrder()
```

Retrieve a menu item's sort order.

**Returns** `int`

### setClass

```php
public function setClass($cssClassString)
```

Set a menu item's css class definitions.

**Parameters**

| Type | Name | Description |
|  --- | --- | --- |
| `string` | `$cssClassString` |  |


**Returns** `Item`

### getClass

```php
public function getClass()
```

Retrieve a menu item's css class definitions.

**Returns** `string`

### disable

```php
public function disable()
```

Set a menu item as disabled.

**Returns** `Item`

### enable

```php
public function enable()
```

Set a menu item as enabled.

**Returns** `Item`

### isDisabled

```php
public function isDisabled()
```

Retrieve if a menu item is disabled.

**Returns** `bool`

### getExtras

```php
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

```php
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`

### setExtras

```php
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**

| Type | Name | Description |
|  --- | --- | --- |
| `array` | `$extras` |  |


**Returns** `Item`

### setExtra

```php
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**

| Type | Name | Description |
|  --- | --- | --- |
| `string` | `$name` |  |
| `mixed` | `$value` |  |


**Returns** `Item`

### setIcon

```php
public function setIcon($icon)
```

Set the icon displayed next to a menu item.

**Parameters**

| Type | Name | Description |
|  --- | --- | --- |
| `string` | `$icon` |  |


**Returns** `Item`

### getIcon

```php
public function getIcon()
```

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

**Returns** `string`

### hasIcon

```php
public function hasIcon()
```

Determine if a menu item has an icon.

**Returns** `bool`

### hasFontAwesomeIcon

```php
public function hasFontAwesomeIcon()
```

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

**Returns** `bool`

### hasGlyphicon

```php
public function hasGlyphicon()
```

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

**Returns** `bool`

### getBodyHtml

```php
public function getBodyHtml()
```

Retrieve a menu item's body HTML content.

**Returns** `string`

### setBodyHtml

```php
public function setBodyHtml($html)
```

Set a menu item's body HTML content.

**Parameters**

| Type | Name | Description |
|  --- | --- | --- |
| `string` | `$html` |  |


**Returns** `Item`

### hasBodyHtml

```php
public function hasBodyHtml()
```

Determine if a menu item has body HTML.

**Returns** `bool`

### getFooterHtml

```php
public function getFooterHtml()
```

Retrieve a menu item's footer HTML content.

**Returns** `string`

### setFooterHtml

```php
public function setFooterHtml($html)
```

Set a menu item's footer HTML content.

**Parameters**

| Type | Name | Description |
|  --- | --- | --- |
| `string` | `$html` |  |


**Returns** `Item`

### hasFooterHtml

```php
public function hasFooterHtml()
```

Determine if a menu item has footer HTML.

**Returns** `bool`

### getHeadingHtml

```php
public function getHeadingHtml()
```

Retrieve a menu item's heading HTML content.

**Returns** `string`

### setHeadingHtml

```php
public function setHeadingHtml($html)
```

Set a menu item's heading HTML content.

**Parameters**

| Type | Name | Description |
|  --- | --- | --- |
| `string` | `$html` |  |


**Returns** `Item`

### hasHeadingHtml

```php
public function hasHeadingHtml()
```

Determine if a menu item has heading HTML.

**Returns** `bool`

### getId

```php
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

```php
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`

### moveUp

```php
public function moveUp()
```

Move a menu item up in sorting order.

**Returns** `Item`

### moveDown

```php
public function moveDown()
```

Move a menu item down in sorting order.

**Returns** `Item`

### moveToFront

```php
public function moveToFront()
```

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

**Returns** `Item`

### moveToBack

```php
public function moveToBack()
```

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

**Returns** `Item`