Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'knp_menu.html.twig' %}
{% extends '@KnpMenu/menu.html.twig' %}

{% block root %}
<ul class="sidebar navbar-nav">
Expand Down Expand Up @@ -44,13 +44,15 @@
{%- if classes is not empty %}
{%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
{%- endif %}

{% if item.hasChildren %}
<li class="nav-item {% if attributes.class is defined %}{{ attributes.class }}{% endif %}">
<a class="nav-link dropdown-toggle {{ is_active ? 'show' : '' }}" href="#navbar-{{ item.name }}" data-bs-toggle="dropdown" data-bs-auto-close="false" role="button" aria-expanded="{{ is_active ? 'true' : 'false' }}">
<span class="nav-link-icon d-md-none d-lg-inline-block">
{{ block('icon') }}
</span>
<span class="nav-link-title">{{ item.label|trans }}</span>

<span class="nav-link-title">{{ block('label') }}</span>
</a>
<div class="dropdown-menu {{ is_active ? 'show' : '' }}">
<div class="dropdown-menu-columns">
Expand All @@ -67,7 +69,7 @@
{{ block('icon') }}
</span>
<span class="nav-link-title">
{{ item.label|trans }} {% if target == '_blank' %}{{ ux_icon('tabler:external-link', {'class': 'icon icon-sm ms-1 mb-2 opacity-75'}) }}{% endif %}
{{ block('label') }} {% if target == '_blank' %}{{ ux_icon('tabler:external-link', {'class': 'icon icon-sm ms-1 mb-2 opacity-75'}) }}{% endif %}
</span>
</a>
</li>
Expand All @@ -92,7 +94,7 @@
{%- endif %}

<a class="dropdown-item {% if attributes.class is defined %}{{ attributes.class }}{% endif %}" href="{{ item.uri }}" target="{{ target }}">
{{ item.label|trans }}{% if target == '_blank' %}{{ ux_icon('tabler:external-link', {'class': 'icon icon-sm ms-1 mb-2 opacity-75'}) }}{% endif %}
{{ block('label') }}{% if target == '_blank' %}{{ ux_icon('tabler:external-link', {'class': 'icon icon-sm ms-1 mb-2 opacity-75'}) }}{% endif %}
</a>
{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace TestApplication\Sylius\BootstrapAdminUi\Menu;

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 class AdminMenuBuilder implements MenuBuilderInterface
{
public function __construct(private MenuBuilderInterface $menuBuilder)
{
}

public function createMenu(array $options): ItemInterface
{
$menu = $this->menuBuilder->createMenu($options);

$menu
->addChild('dashboard', [
'route' => 'sylius_admin_ui_dashboard',
])
->setLabel('app.ui.dashboard')
->setLabelAttribute('icon', 'tabler:dashboard')
;

$this->addLibrarySubMenu($menu);

return $menu;
}

private function addLibrarySubMenu(ItemInterface $menu): void
{
$library = $menu
->addChild('library')
->setLabel('app.menu.library')
->setLabelAttribute('icon', 'tabler:books')
->setExtra('translation_domain', 'menu')
;

$library->addChild('books', ['route' => 'app_book_index'])
->setLabel('app.ui.books')
->setLabelAttribute('icon', 'book')
;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
app:
menu:
library: Library
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
app:
ui:
dashboard: Dashboard
12 changes: 8 additions & 4 deletions src/BootstrapAdminUi/tests/Functional/TemplatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ public function testIndexTemplate(): void
{
$this->client->request('GET', '/books');

self::assertResponseIsSuccessful();
self::assertSelectorTextContains('title', 'app.ui.books | Sylius');
self::assertSelectorTextContains('tr.item:first-child[data-test-resource-id]', 'The Shining');
self::assertSelectorTextContains('tr.item:last-child[data-test-resource-id]', 'Carrie');
$this->assertResponseIsSuccessful();
$this->assertSelectorTextContains('title', 'app.ui.books | Sylius');
$this->assertSelectorTextContains('tr.item:first-child[data-test-resource-id]', 'The Shining');
$this->assertSelectorTextContains('tr.item:last-child[data-test-resource-id]', 'Carrie');

// Test the translation domain on menu
$this->assertAnySelectorTextSame('.nav-link-title', 'Dashboard'); // with "messages" domain
$this->assertAnySelectorTextSame('.nav-link-title', 'Library'); // with "menu" domain
}
}