Completed
Push — master ( 465cbc...56a155 )
by
unknown
12:24
created

MenuBuilderListener::addProviderMenuChild()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
ccs 0
cts 0
cp 0
cc 1
eloc 11
nc 1
nop 6
crap 2
1
<?php
2
3
namespace MediaMonks\SonataMediaBundle\EventListener;
4
5
use Knp\Menu\ItemInterface;
6
use MediaMonks\SonataMediaBundle\Provider\ProviderPool;
7
use Sonata\AdminBundle\Event\ConfigureMenuEvent;
8
use Symfony\Component\Translation\TranslatorInterface;
9
10
class MenuBuilderListener
11
{
12
    /**
13
     * @var ProviderPool
14
     */
15
    private $providerPool;
16
17
    /**
18
     * @var TranslatorInterface
19
     */
20
    private $translator;
21
22
    /**
23
     * @param ProviderPool $providerPool
24
     * @param TranslatorInterface $translator
25
     */
26
    public function __construct(
27
        ProviderPool $providerPool,
28
        TranslatorInterface $translator
29
    ) {
30
        $this->providerPool = $providerPool;
31
        $this->translator = $translator;
32
    }
33
34
    /**
35
     * @param ConfigureMenuEvent $event
36
     */
37
    public function addMenuItems(ConfigureMenuEvent $event)
38
    {
39
        $menu = $event->getMenu();
40
41
        $child = $menu->getChild($this->translator->trans('menu.title'));
42
43
        /*$this->addProviderMenuChild(
0 ignored issues
show
Unused Code Comprehensibility introduced by
68% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
44
            $child,
45
            'batch',
46
            'mediamonks_media_batch',
47
            [],
48
            'batch',
49
            'fa fa-magic'
50
        );*/
51
52
        foreach ($this->providerPool->getProviders() as $providerClass => $provider) {
53
            $this->addProviderMenuChild(
54
                $child,
55
                'provider_'.spl_object_hash($provider),
56
                'admin_mediamonks_sonatamedia_media_create',
57
                ['provider' => $providerClass],
58
                $provider->getName(),
59
                $provider->getIcon()
60
            );
61
        }
62
    }
63
64
    /**
65
     * @param ItemInterface $menu
66
     * @param $route
67
     * @param $routeParameters
68
     * @param $label
69
     * @param $icon
70
     */
71
    private function addProviderMenuChild($menu, $name, $route, $routeParameters, $label, $icon)
72
    {
73
        $child = $menu->addChild(
74
            $name,
75
            [
76
                'route' => $route,
77
                'routeParameters' => $routeParameters,
78
            ]
79
        );
80
        $child->setLabel($this->translator->trans(
81
            'menu.provider',
82
            [
83
                '%provider%' => $this->translator->trans($label),
84
            ]
85
        ));
86
        $child->setAttribute(
87
            'icon',
88
            sprintf('<i class="%s" aria-hidden="true"></i>', $icon)
89
        );
90
91
    }
92
}
93