Skip to content

Commit

Permalink
[Docs] Improve menu customization
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Dec 23, 2024
1 parent 0292696 commit 7662935
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/Menu/AdminMenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private function addLibrarySubMenu(ItemInterface $menu): void
$library = $menu
->addChild('library')
->setLabel('app.ui.library')
->setLabelAttribute('icon', 'tabler:users')
->setLabelAttribute('icon', 'tabler:books')
;

$library->addChild('books', ['route' => 'app_admin_book_index'])
Expand Down
Binary file added docs/.gitbook/assets/sidebar_menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/.gitbook/assets/submenu_items.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions docs/cookbook/admin_panel/menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## How to customize the sidebar menu

### Decorate the sidebar menu

<div data-full-width="false">

<figure><img src="../../.gitbook/assets/sidebar_menu.png" alt="Sidebar menu"></figure>

</div>

To customize the admin menu, you need to decorate the `sylius_admin_ui.knp.menu_builder` service.

```php
Expand Down Expand Up @@ -38,3 +46,46 @@ final readonly class MenuBuilder implements MenuBuilderInterface
}
}
```

### Add submenu items

<div data-full-width="false">

<figure><img src="../../.gitbook/assets/submenu_items.png" alt="Submenu items"></figure>

</div>

Now you can add submenu items:

```php
#[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')
;
}
}
```

0 comments on commit 7662935

Please sign in to comment.