1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
// src/EventListener/MenuBuilderListener.php
namespace App\EventListener;
use App\Entity\GlobalParameter;
use App\Entity\SolidoumeParameter;
use Doctrine\ORM\EntityManagerInterface;
use Knp\Menu\Util\MenuManipulator;
use Sonata\AdminBundle\Event\ConfigureMenuEvent;
final class MenuBuilderListener
{
private $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function addMenuItems(ConfigureMenuEvent $event): void
{
$menu = $event->getMenu();
$useHelloasso = $this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::USE_HELLOASSO);
if ('true' == $useHelloasso) {
$child = $menu->addChild('helloasso', [
'label' => 'HelloAsso',
'route' => 'helloasso_list',
])->setExtras([
'icon' => '<i class="fa fa-bookmark-o"></i>',
]);
$manipulator = new MenuManipulator();
$manipulator->moveToPosition($child, 7);
}
$useSolidoume = $this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::USE_SOLIDOUME);
$soliParam = $this->em->getRepository(SolidoumeParameter::class)->findTheOne();
$name = 'Sécurité sociale alimentaire';
if (!empty($soliParam)) {
$name = $soliParam->getName();
}
if ('true' == $useSolidoume) {
$childS = $menu->addChild('solidoume', [
'label' => $name,
'route' => 'solidoume_list',
])->setExtras([
'icon' => '<i class="fa fa-handshake-o"></i>',
]);
$manipulator = new MenuManipulator();
$manipulator->moveToPosition($childS, 8);
}
}
}