Backend menu model
@api
- Since
- 100.0.2
Definition at line 20 of file Menu.php.
◆ __construct()
__construct |
( |
LoggerInterface |
$logger, |
|
|
|
$pathInMenuStructure = '' , |
|
|
Factory |
$menuItemFactory = null , |
|
|
SerializerInterface |
$serializer = null |
|
) |
| |
Menu constructor
- Parameters
-
LoggerInterface | $logger | |
string | $pathInMenuStructure | |
Factory | null | $menuItemFactory | |
SerializerInterface | null | $serializer | |
Definition at line 52 of file Menu.php.
58 if ($pathInMenuStructure) {
59 $this->_path = $pathInMenuStructure .
'/';
62 $this->setIteratorClass(\
Magento\Backend\Model\Menu\Iterator::class);
64 ->create(Factory::class);
◆ add()
add |
( |
Item |
$item, |
|
|
|
$parentId = null , |
|
|
|
$index = null |
|
) |
| |
Add child to menu item
- Parameters
-
Item | $item | |
string | $parentId | |
int | $index | |
- Returns
- void
- Exceptions
-
Definition at line 77 of file Menu.php.
79 if ($parentId !==
null) {
80 $parentItem = $this->
get($parentId);
81 if ($parentItem ===
null) {
82 throw new \InvalidArgumentException(
"Item with identifier {$parentId} does not exist");
84 $parentItem->getChildren()->add(
$item,
null,
$index);
87 if (!isset($this[
$index])) {
90 sprintf(
'Add of item with id %s was processed',
$item->getId())
◆ getParentItems()
getParentItems |
( |
|
$itemId | ) |
|
Get parent items by item id
- Parameters
-
- Returns
- Item[]
Definition at line 233 of file Menu.php.
236 $this->_findParentItems($this, $itemId, $parents);
237 return array_reverse($parents);
◆ isLast()
Check whether provided item is last in list
- Parameters
-
- Returns
- bool
Definition at line 197 of file Menu.php.
199 return $this->offsetGet(max(array_keys($this->getArrayCopy())))->getId() ==
$item->getId();
◆ move()
move |
( |
|
$itemId, |
|
|
|
$toItemId, |
|
|
|
$sortIndex = null |
|
) |
| |
Move menu item
- Parameters
-
string | $itemId | |
string | $toItemId | |
int | $sortIndex | |
- Returns
- void
- Exceptions
-
Definition at line 130 of file Menu.php.
132 $item = $this->
get($itemId);
133 if (
$item ===
null) {
134 throw new \InvalidArgumentException(
"Item with identifier {$itemId} does not exist");
136 $this->
remove($itemId);
137 $this->
add(
$item, $toItemId, $sortIndex);
◆ populateFromArray()
populateFromArray |
( |
array |
$data | ) |
|
Populate the menu with data from array
- Parameters
-
- Returns
- void
- Since
- 100.2.0
Definition at line 310 of file Menu.php.
313 foreach (
$data as $itemData) {
314 $item = $this->menuItemFactory->create($itemData);
317 $this->exchangeArray(
$items);
◆ serialize()
Serialize menu
- Returns
- string
Definition at line 270 of file Menu.php.
272 return $this->serializer->serialize($this->
toArray());
◆ toArray()
Get menu data represented as an array
- Returns
- array
- Since
- 100.2.0
Definition at line 281 of file Menu.php.
284 foreach ($this as
$item) {
◆ unserialize()
unserialize |
( |
|
$serialized | ) |
|
Unserialize menu
- Parameters
-
- Returns
- void
- Since
- 100.2.0
Definition at line 297 of file Menu.php.
299 $data = $this->serializer->unserialize($serialized);
◆ $_logger
◆ $_path
The documentation for this class was generated from the following file:
- vendor/magento/module-backend/Model/Menu.php