|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LAG\AdminBundle\Event\Listener\Menu; |
|
6
|
|
|
|
|
7
|
|
|
use LAG\AdminBundle\Admin\Helper\AdminHelperInterface; |
|
8
|
|
|
use LAG\AdminBundle\Event\Events\MenuEvent; |
|
9
|
|
|
use LAG\AdminBundle\Menu\Factory\MenuItemFactoryInterface; |
|
10
|
|
|
use LAG\AdminBundle\Translation\Helper\TranslationHelperInterface; |
|
11
|
|
|
|
|
12
|
|
|
class CreateTopMenuListener |
|
13
|
|
|
{ |
|
14
|
|
|
private AdminHelperInterface $adminHelper; |
|
15
|
|
|
private TranslationHelperInterface $translationHelper; |
|
16
|
|
|
private MenuItemFactoryInterface $menuItemFactory; |
|
17
|
|
|
|
|
18
|
|
|
public function __construct( |
|
19
|
|
|
AdminHelperInterface $adminHelper, |
|
20
|
|
|
TranslationHelperInterface $translationHelper, |
|
21
|
|
|
MenuItemFactoryInterface $menuItemFactory |
|
22
|
|
|
) { |
|
23
|
|
|
$this->adminHelper = $adminHelper; |
|
24
|
|
|
$this->translationHelper = $translationHelper; |
|
25
|
|
|
$this->menuItemFactory = $menuItemFactory; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function __invoke(MenuEvent $event): void |
|
29
|
|
|
{ |
|
30
|
|
|
if ($event->getMenuName() !== 'top' || !$this->adminHelper->hasAdmin()) { |
|
31
|
|
|
return; |
|
32
|
|
|
} |
|
33
|
|
|
$admin = $this->adminHelper->getAdmin(); |
|
34
|
|
|
$menu = $event->getMenu(); |
|
35
|
|
|
|
|
36
|
|
|
// Do not add the return link when we already are on the list action |
|
37
|
|
|
if (!$admin->getAction()->getConfiguration()->shouldAddReturnLink()) { |
|
38
|
|
|
return; |
|
39
|
|
|
} |
|
40
|
|
|
$child = $this->menuItemFactory->create('return', [ |
|
41
|
|
|
'admin' => $admin->getName(), |
|
42
|
|
|
'action' => 'list', |
|
43
|
|
|
'text' => $this->translationHelper->transWithPattern('return', [], null, null, null, 'ui'), |
|
44
|
|
|
'icon' => 'fas fa-arrow-left', |
|
45
|
|
|
'linkAttributes' => ['class' => 'btn btn-info btn-icon-split btn-sm'], |
|
46
|
|
|
]); |
|
47
|
|
|
$menu->addChild($child); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|