|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Sylius package. |
| 5 | + * |
| 6 | + * (c) Sylius Sp. z o.o. |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespace TestApplication\Sylius\BootstrapAdminUi\Menu; |
| 15 | + |
| 16 | +use Knp\Menu\ItemInterface; |
| 17 | +use Sylius\AdminUi\Knp\Menu\MenuBuilderInterface; |
| 18 | +use Symfony\Component\DependencyInjection\Attribute\AsDecorator; |
| 19 | + |
| 20 | +#[AsDecorator(decorates: 'sylius_admin_ui.knp.menu_builder')] |
| 21 | +final class AdminMenuBuilder implements MenuBuilderInterface |
| 22 | +{ |
| 23 | + public function __construct(private MenuBuilderInterface $menuBuilder) |
| 24 | + { |
| 25 | + } |
| 26 | + |
| 27 | + public function createMenu(array $options): ItemInterface |
| 28 | + { |
| 29 | + $menu = $this->menuBuilder->createMenu($options); |
| 30 | + |
| 31 | + $menu |
| 32 | + ->addChild('dashboard', [ |
| 33 | + 'route' => 'sylius_admin_ui_dashboard', |
| 34 | + ]) |
| 35 | + ->setLabel('app.ui.dashboard') |
| 36 | + ->setLabelAttribute('icon', 'tabler:dashboard') |
| 37 | + ; |
| 38 | + |
| 39 | + $this->addLibrarySubMenu($menu); |
| 40 | + |
| 41 | + return $menu; |
| 42 | + } |
| 43 | + |
| 44 | + private function addLibrarySubMenu(ItemInterface $menu): void |
| 45 | + { |
| 46 | + $library = $menu |
| 47 | + ->addChild('library') |
| 48 | + ->setLabel('app.menu.library') |
| 49 | + ->setLabelAttribute('icon', 'tabler:books') |
| 50 | + ->setExtra('translation_domain', 'menu') |
| 51 | + ; |
| 52 | + |
| 53 | + $library->addChild('books', ['route' => 'app_book_index']) |
| 54 | + ->setLabel('app.ui.books') |
| 55 | + ->setLabelAttribute('icon', 'book') |
| 56 | + ; |
| 57 | + } |
| 58 | +} |
0 commit comments