Skip to content

Commit 3b2fcec

Browse files
authored
Merge pull request #28 from sumocoders/menu
Add users to menu listener
2 parents 13c2904 + 7b30c5e commit 3b2fcec

File tree

5 files changed

+42
-3
lines changed

5 files changed

+42
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
How to use:
44
* Copy each `User` folder from the respective `src/` folder into your own project.
55
* Copy the `Security` folder from `src/` into your own project.
6+
* Copy the `EventListener` folder from `src/` into your own project.
67
* Copy `template/user` into your own project.
78
* Copy the `config/packages/security.yaml` into your own project.
89
* Copy the MySQL migration and run it.

src/Controller/User/Admin/OverviewController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class OverviewController extends AbstractController
1616
{
1717
#[Route('/admin/users', name: 'user_overview')]
18-
#[Breadcrumb('users')]
18+
#[Breadcrumb('Users')]
1919
public function __invoke(
2020
Request $request,
2121
UserRepository $userRepository,

src/EventListener/MenuListener.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace App\EventListener;
4+
5+
use SumoCoders\FrameworkCoreBundle\Event\ConfigureMenuEvent;
6+
use SumoCoders\FrameworkCoreBundle\EventListener\DefaultMenuListener;
7+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8+
9+
final class MenuListener extends DefaultMenuListener implements EventSubscriberInterface
10+
{
11+
public function onConfigureMenu(ConfigureMenuEvent $event): void
12+
{
13+
$factory = $event->getFactory();
14+
$menu = $event->getMenu();
15+
16+
if ($this->getSecurity()->isGranted('ROLE_ADMIN')) {
17+
$menu->addChild(
18+
$factory->createItem(
19+
$this->getTranslator()->trans('Users'),
20+
[
21+
'route' => 'user_overview',
22+
'labelAttributes' => [
23+
'icon' => 'fas fa-user',
24+
],
25+
],
26+
)
27+
);
28+
}
29+
}
30+
31+
/**
32+
* @return array<string, mixed>
33+
*/
34+
public static function getSubscribedEvents(): array
35+
{
36+
return [ConfigureMenuEvent::EVENT_NAME => 'onConfigureMenu'];
37+
}
38+
}

templates/user/admin/overview.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% extends 'base.html.twig' %}
22

33
{% block header_title %}
4-
<h1>{{ 'users'|trans }}</h1>
4+
<h1>{{ 'Users'|trans }}</h1>
55
{% endblock %}
66

77
{% block header_navigation %}

translations/messages+intl-icu.nl.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Disable: Blokkeer
2121
Enable: Activeer
2222
Save: Opslaan
23-
users: Gebruikers
23+
Users: Gebruikers
2424
Username: Gebruikersnaam
2525
Roles: Rollen
2626
Confirmed: Bevestigd

0 commit comments

Comments
 (0)