declare(strict_types=1);
namespace App\Menu;
use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Sylius\AdminUi\Knp\Menu\MenuBuilderInterface;
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
#[AsDecorator(decorates: 'sylius_admin_ui.knp.menu_builder')]
final readonly class MenuBuilder implements MenuBuilderInterface
{
public function __construct(
private readonly FactoryInterface $factory,
) {
}
public function createMenu(array $options): ItemInterface
{
$menu = $this->factory->createItem('root');
$menu
->addChild('dashboard', [
'route' => 'sylius_admin_ui_dashboard',
])
->setLabel('sylius.ui.dashboard')
->setLabelAttribute('icon', 'tabler:dashboard')
;
return $menu;
}
}
// ...
#[AsDecorator(decorates: 'sylius_admin_ui.knp.menu_builder')]
final readonly class MenuBuilder implements MenuBuilderInterface
{
// ...
public function createMenu(array $options): ItemInterface
{
$menu = $this->factory->createItem('root');
// ...
$this->addLibrarySubMenu($menu);
return $menu;
}
private function addLibrarySubMenu(ItemInterface $menu): void
{
$library = $menu
->addChild('library')
->setLabel('app.ui.library')
->setLabelAttribute('icon', 'tabler:books')
;
$library->addChild('books', ['route' => 'app_admin_book_index'])
->setLabel('app.ui.books')
->setLabelAttribute('icon', 'book')
;
}
}