From 57785404dbcbf70ecb4c91ead3a7661449471647 Mon Sep 17 00:00:00 2001 From: jkindly Date: Fri, 2 Aug 2024 08:53:50 +0200 Subject: [PATCH] OP-463: Move CMS menu under marketing --- src/Menu/ContentManagementMenuBuilder.php | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Menu/ContentManagementMenuBuilder.php b/src/Menu/ContentManagementMenuBuilder.php index 8862823f..c0e25f11 100755 --- a/src/Menu/ContentManagementMenuBuilder.php +++ b/src/Menu/ContentManagementMenuBuilder.php @@ -10,6 +10,7 @@ namespace BitBag\SyliusCmsPlugin\Menu; +use Knp\Menu\ItemInterface; use Sylius\Bundle\UiBundle\Menu\Event\MenuBuilderEvent; final class ContentManagementMenuBuilder @@ -62,5 +63,29 @@ public function buildMenu(MenuBuilderEvent $menuBuilderEvent): void ->setLabel('bitbag_sylius_cms_plugin.ui.media') ->setLabelAttribute('icon', 'file') ; + + $this->reorderMenu($menu, 'bitbag_cms', 'marketing'); + } + + private function reorderMenu(ItemInterface $menu, string $newItemKey, string $targetItemKey): void + { + $menuItems = $menu->getChildren(); + + $newMenuItem = $menu->getChild($newItemKey); + unset($menuItems[$newItemKey]); + + $targetPosition = array_search($targetItemKey, array_keys($menuItems), true); + + if (null !== $newMenuItem && false !== $targetPosition) { + $menuItems = array_slice($menuItems, 0, $targetPosition + 1, true) + + [$newItemKey => $newMenuItem] + + array_slice($menuItems, $targetPosition + 1, null, true); + + $menuItems = array_filter($menuItems, static function ($item) { + return $item instanceof ItemInterface; + }); + + $menu->setChildren($menuItems); + } } }