Skip to content

Commit

Permalink
OP-463: Move CMS menu under marketing
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Aug 2, 2024
1 parent 3ac5538 commit 5778540
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Menu/ContentManagementMenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace BitBag\SyliusCmsPlugin\Menu;

use Knp\Menu\ItemInterface;
use Sylius\Bundle\UiBundle\Menu\Event\MenuBuilderEvent;

final class ContentManagementMenuBuilder
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 5778540

Please sign in to comment.