NavigationListener   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 0
loc 50
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
D onNavigationConfigure() 0 28 9
1
<?php
2
3
namespace Oro\Bundle\ChannelBundle\EventListener;
4
5
use Oro\Bundle\NavigationBundle\Event\ConfigureMenuEvent;
6
use Oro\Bundle\ChannelBundle\Provider\SettingsProvider;
7
use Oro\Bundle\ChannelBundle\Provider\StateProvider;
8
9
/**
10
 * Hide menu items that were not enabled it config
11
 */
12
class NavigationListener
13
{
14
    /** @var SettingsProvider */
15
    protected $settings;
16
17
    /** @var StateProvider */
18
    protected $state;
19
20
    /**
21
     * @param SettingsProvider $settings
22
     * @param StateProvider    $state
23
     */
24
    public function __construct(SettingsProvider $settings, StateProvider $state)
25
    {
26
        $this->settings = $settings;
27
        $this->state    = $state;
28
    }
29
30
    /**
31
     * @param ConfigureMenuEvent $event
32
     */
33
    public function onNavigationConfigure(ConfigureMenuEvent $event)
34
    {
35
        foreach ((array) $this->settings->getSettings(SettingsProvider::DATA_PATH) as $setting) {
36
            if (!$this->state->isEntityEnabled($setting['name'])) {
37
                continue;
38
            }
39
40
            foreach ($setting['navigation_items'] as $item) {
41
                $navigateArray = explode('.', $item);
42
                $menu = $event->getMenu();
43
44
                if ($menu->getName() !== $navigateArray[0]) {
45
                    continue;
46
                }
47
48
                $navigateArrayCount = count($navigateArray);
49
                for ($i = 1; $i < $navigateArrayCount; $i++) {
50
                    if ($menu->getChild($navigateArray[$i])) {
51
                        /** redefinition of variable $menu */
52
                        $menu = $menu->getChild($navigateArray[$i]);
53
                    }
54
                    if ($menu && !$menu->isDisplayed()) {
55
                        $menu->setDisplay(true);
56
                    }
57
                }
58
            }
59
        }
60
    }
61
}
62