Completed
Push — master ( 79038f...70e595 )
by Łukasz
21s
created

TwigBulkActionGridRenderer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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
declare(strict_types=1);
13
14
namespace Sylius\Bundle\GridBundle\Renderer;
15
16
use Sylius\Component\Grid\Definition\Action;
17
use Sylius\Component\Grid\Renderer\BulkActionGridRendererInterface;
18
use Sylius\Component\Grid\View\GridViewInterface;
19
20
final class TwigBulkActionGridRenderer implements BulkActionGridRendererInterface
21
{
22
    /**
23
     * @var \Twig_Environment
24
     */
25
    private $twig;
26
27
    /**
28
     * @var array
29
     */
30
    private $bulkActionTemplates;
31
32
    public function __construct(\Twig_Environment $twig, array $bulkActionTemplates)
33
    {
34
        $this->twig = $twig;
35
        $this->bulkActionTemplates = $bulkActionTemplates;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function renderBulkAction(GridViewInterface $gridView, Action $bulkAction, $data = null): string
42
    {
43
        $type = $bulkAction->getType();
44
        if (!isset($this->bulkActionTemplates[$type])) {
45
            throw new \InvalidArgumentException(sprintf('Missing template for bulk action type "%s".', $type));
46
        }
47
48
        return $this->twig->render($this->bulkActionTemplates[$type], [
49
            'grid' => $gridView,
50
            'action' => $bulkAction,
51
            'data' => $data,
52
        ]);
53
    }
54
}
55