|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MediaMonks\SonataMediaBundle\EventListener; |
|
4
|
|
|
|
|
5
|
|
|
use MediaMonks\SonataMediaBundle\Provider\ProviderPool; |
|
6
|
|
|
use Sonata\AdminBundle\Event\ConfigureMenuEvent; |
|
7
|
|
|
use Symfony\Component\Translation\TranslatorInterface; |
|
8
|
|
|
|
|
9
|
|
|
class MenuBuilderListener |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var ProviderPool |
|
13
|
|
|
*/ |
|
14
|
|
|
private $providerPool; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var TranslatorInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
private $translator; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param ProviderPool $providerPool |
|
23
|
|
|
* @param TranslatorInterface $translator |
|
24
|
|
|
*/ |
|
25
|
|
|
public function __construct( |
|
26
|
|
|
ProviderPool $providerPool, |
|
27
|
|
|
TranslatorInterface $translator |
|
28
|
|
|
) { |
|
29
|
|
|
$this->providerPool = $providerPool; |
|
30
|
|
|
$this->translator = $translator; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param ConfigureMenuEvent $event |
|
35
|
|
|
*/ |
|
36
|
|
|
public function addMenuItems(ConfigureMenuEvent $event) |
|
37
|
|
|
{ |
|
38
|
|
|
$menu = $event->getMenu(); |
|
39
|
|
|
|
|
40
|
|
|
$child = $menu->getChild('Media'); |
|
41
|
|
|
|
|
42
|
|
|
foreach ($this->providerPool->getProviders( |
|
43
|
|
|
) as $providerClass => $provider) { |
|
44
|
|
|
$providerChild = $child->addChild( |
|
45
|
|
|
'provider_'.spl_object_hash($provider), |
|
46
|
|
|
[ |
|
47
|
|
|
'route' => 'admin_mediamonks_sonatamedia_media_create', |
|
48
|
|
|
'routeParameters' => [ |
|
49
|
|
|
'provider' => $providerClass, |
|
50
|
|
|
], |
|
51
|
|
|
] |
|
52
|
|
|
); |
|
53
|
|
|
$providerChild->setAttribute( |
|
54
|
|
|
'icon', |
|
55
|
|
|
sprintf( |
|
56
|
|
|
'<i class="%s" aria-hidden="true"></i>', |
|
57
|
|
|
$provider->getIcon() |
|
58
|
|
|
) |
|
59
|
|
|
); |
|
60
|
|
|
$providerChild->setLabel( |
|
61
|
|
|
$this->translator->trans( |
|
62
|
|
|
'menu.provider', |
|
63
|
|
|
[ |
|
64
|
|
|
'%provider%' => $this->translator->trans($provider->getName()) |
|
65
|
|
|
] |
|
66
|
|
|
) |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|