Completed
Pull Request — master (#311)
by Łukasz
03:20
created

ItemElementsDecorator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * (c) FSi sp. z o.o. <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FSi\Bundle\AdminBundle\Menu\KnpMenu;
13
14
use FSi\Bundle\AdminBundle\Admin\Element;
15
use FSi\Bundle\AdminBundle\Menu\Item\ElementItem;
16
use FSi\Bundle\AdminBundle\Menu\Item\Item as AdminMenuItem;
17
use Knp\Menu\ItemInterface as KnpMenuItem;
18
19
class ItemElementsDecorator implements ItemDecorator
20
{
21
    public function decorate(KnpMenuItem $knpMenuItem, AdminMenuItem $adminMenuItem): void
22
    {
23
        if ($adminMenuItem instanceof ElementItem && $adminMenuItem->hasOption('elements')) {
24
            $routes = $knpMenuItem->getExtra('routes', []);
25
26
            /** @var Element[] $elements */
27
            $elements = $adminMenuItem->getOption('elements');
28
            foreach ($elements as $element) {
29
                $routes[] = [
30
                    'route' => $element->getRoute(),
31
                    'parameters' => $element->getRouteParameters()
32
                ];
33
            }
34
35
            $knpMenuItem->setExtra('routes', $routes);
36
        }
37
    }
38
}
39