Skip to content

Commit

Permalink
Init navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Oct 4, 2024
1 parent 12ab4e6 commit f8bd194
Show file tree
Hide file tree
Showing 14 changed files with 187 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/BootstrapAdminUi/config/app/twig_hooks/common/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand Down
3 changes: 3 additions & 0 deletions src/BootstrapAdminUi/config/app/twig_hooks/common/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand Down
3 changes: 3 additions & 0 deletions src/BootstrapAdminUi/config/app/twig_hooks/common/show.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand Down
3 changes: 3 additions & 0 deletions src/BootstrapAdminUi/config/app/twig_hooks/common/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand Down
35 changes: 35 additions & 0 deletions src/BootstrapAdminUi/config/app/twig_hooks/layout/navbar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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 Symfony\Component\DependencyInjection\Loader\Configurator;

return static function (ContainerConfigurator $container): void {
$container->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',
],
],
],
]);
};
18 changes: 18 additions & 0 deletions src/BootstrapAdminUi/config/services.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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 Symfony\Component\DependencyInjection\Loader\Configurator;

return function (ContainerConfigurator $configurator): void {
$configurator->import('./services/**/**.php');
};
32 changes: 32 additions & 0 deletions src/BootstrapAdminUi/config/services/twig/component.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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 Symfony\Component\DependencyInjection\Loader\Configurator;

use Sylius\BootstrapAdminUi\Twig\Component\UserDropdownComponent;

return function (ContainerConfigurator $configurator): void {
$services = $configurator->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',
]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
52 changes: 52 additions & 0 deletions src/BootstrapAdminUi/src/Twig/Component/UserDropdownComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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 Sylius\BootstrapAdminUi\Twig\Component;

use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
use Symfony\UX\TwigComponent\Attribute\ExposeInTemplate;

#[AsTwigComponent]
class UserDropdownComponent
{
public function __construct(
private readonly array $routing,
private TokenStorageInterface $tokenStorage,
private RouterInterface $router,
) {
}

#[ExposeInTemplate(name: 'user')]
public function getUser(): ?UserInterface
{
return $this->tokenStorage->getToken()?->getUser();
}

/**
* @return array<array-key, array{title?: string, url?: string, icon?: string, type?: string, class?: string}>
*/
#[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',
],
];
}
}
Original file line number Diff line number Diff line change
@@ -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 %}
<div class="d-flex lh-1 text-reset p-0 cursor-pointer">
<div>
{{ avatar.small() }}
</div>
<div class="d-none d-xl-block ps-2">
<div class="mb-1 small text-muted">{{ 'sylius.ui.hello'|trans }}</div>
<div>{{ user.userIdentifier }}</div>
</div>
</div>
{% endset %}

{{ dropdown.list({ customTrigger: dropdown_trigger, direction: 'down-end' }, menu_items) }}
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="nav align-items-center gap-3">
{% hook 'items' %}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="nav-item">
{{ component('sylius_bootstrap_admin_ui:navbar:user_dropdown') }}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div id="navbar-menu">
{% hook 'menu' %}
</div>
2 changes: 2 additions & 0 deletions src/UiTranslations/translations/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f8bd194

Please sign in to comment.