diff --git a/src/BootstrapAdminUi/config/app/twig_hooks/common/create.php b/src/BootstrapAdminUi/config/app/twig_hooks/common/create.php index b523cae3..30206a98 100644 --- a/src/BootstrapAdminUi/config/app/twig_hooks/common/create.php +++ b/src/BootstrapAdminUi/config/app/twig_hooks/common/create.php @@ -20,6 +20,9 @@ 'sidebar' => [ 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/sidebar.html.twig', ], + 'navbar' => [ + 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/navbar.html.twig', + ], 'content' => [ 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/content.html.twig', ], diff --git a/src/BootstrapAdminUi/config/app/twig_hooks/common/index.php b/src/BootstrapAdminUi/config/app/twig_hooks/common/index.php index 0fbbbfce..e612b0db 100644 --- a/src/BootstrapAdminUi/config/app/twig_hooks/common/index.php +++ b/src/BootstrapAdminUi/config/app/twig_hooks/common/index.php @@ -20,6 +20,9 @@ 'sidebar' => [ 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/sidebar.html.twig', ], + 'navbar' => [ + 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/navbar.html.twig', + ], 'content' => [ 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/content.html.twig', ], diff --git a/src/BootstrapAdminUi/config/app/twig_hooks/common/show.php b/src/BootstrapAdminUi/config/app/twig_hooks/common/show.php index 2535a4b9..143d0b85 100644 --- a/src/BootstrapAdminUi/config/app/twig_hooks/common/show.php +++ b/src/BootstrapAdminUi/config/app/twig_hooks/common/show.php @@ -20,6 +20,9 @@ 'sidebar' => [ 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/sidebar.html.twig', ], + 'navbar' => [ + 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/navbar.html.twig', + ], 'content' => [ 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/content.html.twig', ], diff --git a/src/BootstrapAdminUi/config/app/twig_hooks/common/update.php b/src/BootstrapAdminUi/config/app/twig_hooks/common/update.php index 45d0f5f5..deaa708a 100644 --- a/src/BootstrapAdminUi/config/app/twig_hooks/common/update.php +++ b/src/BootstrapAdminUi/config/app/twig_hooks/common/update.php @@ -20,6 +20,9 @@ 'sidebar' => [ 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/sidebar.html.twig', ], + 'navbar' => [ + 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/navbar.html.twig', + ], 'content' => [ 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/content.html.twig', ], diff --git a/src/BootstrapAdminUi/config/app/twig_hooks/layout/navbar.php b/src/BootstrapAdminUi/config/app/twig_hooks/layout/navbar.php new file mode 100644 index 00000000..76a422fc --- /dev/null +++ b/src/BootstrapAdminUi/config/app/twig_hooks/layout/navbar.php @@ -0,0 +1,35 @@ +extension('sylius_twig_hooks', [ + 'hooks' => [ + 'sylius_admin.common.component.navbar' => [ + 'menu' => [ + 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/navbar/menu.html.twig', + ], + 'items' => [ + 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/navbar/items.html.twig', + ], + ], + + 'sylius_admin.common.component.navbar.items' => [ + 'user' => [ + 'template' => '@SyliusBootstrapAdminUi/shared/crud/common/navbar/items/user.html.twig', + ], + ], + ], + ]); +}; diff --git a/src/BootstrapAdminUi/config/services.php b/src/BootstrapAdminUi/config/services.php new file mode 100644 index 00000000..e2411bef --- /dev/null +++ b/src/BootstrapAdminUi/config/services.php @@ -0,0 +1,18 @@ +import('./services/**/**.php'); +}; diff --git a/src/BootstrapAdminUi/config/services/twig/component.php b/src/BootstrapAdminUi/config/services/twig/component.php new file mode 100644 index 00000000..b0c50764 --- /dev/null +++ b/src/BootstrapAdminUi/config/services/twig/component.php @@ -0,0 +1,32 @@ +services(); + + $services->set('sylius_bootstrap_admin_ui.twig.component.navbar.user_dropdown', UserDropdownComponent::class) + ->public() + ->args([ + param('sylius_admin_ui.routing'), + service('security.token_storage'), + service('router'), + ]) + ->tag('twig.component', [ + 'key' => 'sylius_bootstrap_admin_ui:navbar:user_dropdown', + 'template' => '@SyliusBootstrapAdminUi/shared/components/navbar/user.html.twig', + ]); +}; diff --git a/src/BootstrapAdminUi/src/Symfony/SyliusBootstrapAdminUiBundle.php b/src/BootstrapAdminUi/src/Symfony/SyliusBootstrapAdminUiBundle.php index 0e3defe7..ff4fb436 100644 --- a/src/BootstrapAdminUi/src/Symfony/SyliusBootstrapAdminUiBundle.php +++ b/src/BootstrapAdminUi/src/Symfony/SyliusBootstrapAdminUiBundle.php @@ -13,8 +13,10 @@ namespace Sylius\BootstrapAdminUi\Symfony; +use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use Symfony\Component\HttpKernel\Bundle\AbstractBundle; final class SyliusBootstrapAdminUiBundle extends AbstractBundle @@ -33,6 +35,13 @@ public function prependExtension(ContainerConfigurator $container, ContainerBuil { $bundles = $builder->getParameter('kernel.bundles'); + $loader = new PhpFileLoader( + $builder, + new FileLocator(dirname(__DIR__, 2) . '/config'), + ); + + $loader->load('services.php'); + if (!isset($bundles['SyliusAdminUiBundle'])) { return; } diff --git a/src/BootstrapAdminUi/src/Twig/Component/UserDropdownComponent.php b/src/BootstrapAdminUi/src/Twig/Component/UserDropdownComponent.php new file mode 100644 index 00000000..1e90612a --- /dev/null +++ b/src/BootstrapAdminUi/src/Twig/Component/UserDropdownComponent.php @@ -0,0 +1,55 @@ +tokenStorage->getToken()?->getUser(); + } + + /** + * @return array + */ + #[ExposeInTemplate(name: 'menu_items')] + public function getMenuItems(): array + { + return [ + [ + 'title' => 'sylius.ui.logout', + 'url' => $this->routing['logout_path'] ?? $this->router->generate('sylius_admin_ui_logout'), + 'icon' => 'logout', + ], + ]; + } +} diff --git a/src/BootstrapAdminUi/templates/shared/components/navbar/user.html.twig b/src/BootstrapAdminUi/templates/shared/components/navbar/user.html.twig new file mode 100644 index 00000000..6d91276a --- /dev/null +++ b/src/BootstrapAdminUi/templates/shared/components/navbar/user.html.twig @@ -0,0 +1,18 @@ +{% import '@SyliusBootstrapAdminUi/shared/helper/avatar.html.twig' as avatar %} +{% import '@SyliusBootstrapAdminUi/shared/helper/dropdown.html.twig' as dropdown %} + +{% if app.user %} + {% set dropdown_trigger %} +
+
+ {{ avatar.small() }} +
+
+
{{ 'sylius.ui.hello'|trans }}
+
{{ user.userIdentifier }}
+
+
+ {% endset %} + + {{ dropdown.list({ customTrigger: dropdown_trigger, direction: 'down-end' }, menu_items) }} +{% endif %} diff --git a/src/BootstrapAdminUi/templates/shared/crud/common/navbar/items.html.twig b/src/BootstrapAdminUi/templates/shared/crud/common/navbar/items.html.twig new file mode 100644 index 00000000..7334f385 --- /dev/null +++ b/src/BootstrapAdminUi/templates/shared/crud/common/navbar/items.html.twig @@ -0,0 +1,3 @@ + diff --git a/src/BootstrapAdminUi/templates/shared/crud/common/navbar/items/user.html.twig b/src/BootstrapAdminUi/templates/shared/crud/common/navbar/items/user.html.twig new file mode 100644 index 00000000..6282fee1 --- /dev/null +++ b/src/BootstrapAdminUi/templates/shared/crud/common/navbar/items/user.html.twig @@ -0,0 +1,3 @@ + diff --git a/src/BootstrapAdminUi/templates/shared/crud/common/navbar/menu.html.twig b/src/BootstrapAdminUi/templates/shared/crud/common/navbar/menu.html.twig new file mode 100644 index 00000000..e6fc5fc8 --- /dev/null +++ b/src/BootstrapAdminUi/templates/shared/crud/common/navbar/menu.html.twig @@ -0,0 +1,3 @@ + diff --git a/src/UiTranslations/translations/messages.en.yaml b/src/UiTranslations/translations/messages.en.yaml index 6f536695..c8782f28 100644 --- a/src/UiTranslations/translations/messages.en.yaml +++ b/src/UiTranslations/translations/messages.en.yaml @@ -22,9 +22,11 @@ sylius: filter: Filter filters: Filters from: From + hello: Hello info: Info login: Login login_to_your_account: 'Login to your account' + logout: Logout new: New no_label: No no_results: No results found