for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* (c) FSi sp. z o.o. <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace FSi\Bundle\AdminBundle\EventListener;
use FSi\Bundle\AdminBundle\Event\MenuEvent;
use FSi\Bundle\AdminBundle\Menu\Item\RoutableItem;
use FSi\Bundle\AdminBundle\Menu\Item\Item as MenuItem;
class CleanUpMenuListener
{
public function cleanUpMenu(MenuEvent $event)
$this->cleanMenuLevel($event->getMenu());
}
private function cleanMenuLevel(MenuItem $menu): void
if (!$menu->hasChildren()) {
return;
foreach ($menu->getChildren() as $menuItem) {
$this->cleanMenuLevel($menuItem);
if (!$menuItem instanceof RoutableItem && !$menuItem->hasChildren()) {
$menu->removeChild($menuItem->getName());