Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] Improve menu customization #197

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
50 changes: 50 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,45 @@ 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')]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding use here to avoid searching to the wrong class ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, indeed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the "AsDecorator" class on "use" on the previous example.
Here, the important part is to add a new sub menu with items.

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')
;
}
}
```
Loading