AdminShippingGatewayGridEventListener   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 17
dl 0
loc 33
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A editActionLinks() 0 23 3
1
<?php
2
3
/*
4
 * This file was created by developers working at BitBag
5
 * Do you need more information about us and what we do? Visit our https://bitbag.io website!
6
 * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
7
*/
8
9
declare(strict_types=1);
10
11
namespace BitBag\SyliusShippingExportPlugin\EventListener\Grid;
12
13
use Sylius\Component\Grid\Event\GridDefinitionConverterEvent;
14
15
final class AdminShippingGatewayGridEventListener
16
{
17
    /** @var array */
18
    private $shippingGateways;
19
20
    public function __construct(array $shippingGateways)
21
    {
22
        $this->shippingGateways = $shippingGateways;
23
    }
24
25
    public function editActionLinks(GridDefinitionConverterEvent $event): void
26
    {
27
        $grid = $event->getGrid();
28
29
        $actions = $grid->getActions('main');
30
        if (!isset($actions['create'])) {
31
            return;
32
        }
33
        $createAction = $actions['create'];
34
        $options = $createAction->getOptions();
35
36
        foreach ($this->shippingGateways as $shippingGatewayType => $shippingGatewayLabel) {
37
            $options['links'][$shippingGatewayType] = [
38
                'label' => $shippingGatewayLabel,
39
                'icon' => 'plus',
40
                'route' => 'bitbag_admin_shipping_gateway_create',
41
                'parameters' => [
42
                    'code' => $shippingGatewayType,
43
                ],
44
            ];
45
        }
46
47
        $createAction->setOptions($options);
48
    }
49
}
50