Passed
Branch develop (bac6db)
by Ludwig
04:56
created

ImageType::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 17
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 9
nc 2
nop 4
1
<?php
2
/*
3
 * This file is part of cwdFancyGridBundle
4
 *
5
 * (c)2017 cwd.at GmbH <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
declare(strict_types=1);
11
namespace Cwd\FancyGridBundle\Column;
12
13
use Symfony\Component\OptionsResolver\OptionsResolver;
14
15
/**
16
 * Class ImageType
17
 * @package Cwd\FancyGridBundle\Column
18
 * @author Ludwig Ruderstaler <[email protected]>
19
 */
20
class ImageType extends AbstractColumn
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function configureOptions(OptionsResolver $resolver)
26
    {
27
        parent::configureOptions($resolver);
28
29
        $resolver->setDefaults(array(
30
            'type' => 'image',
31
            'minListWidth' => null,
32
            'filter' => [],
33
            'prefix' => null
34
        ));
35
36
        $resolver->setAllowedTypes('attr', 'array');
37
    }
38
39
    /**
40
     * @param mixed             $value
41
     * @param mixed             $object
42
     * @param mixed             $primary
43
     * @param \Twig_Environment $twig
44
     *
45
     * @return mixed
46
     */
47
    public function render($value, $object, $primary, \Twig_Environment $twig)
48
    {
49
        /** dont use twig if no template is provided */
50
        if (null === $this->getOption('template')) {
51
            return $this->getOption('prefix').$value;
52
        }
53
54
        return $this->renderTemplate(
55
            $twig,
56
            $this->getOption('template'),
57
            [
58
                'value'   => $this->getOption('prefux').$value,
59
                'object'  => $object,
60
                'primary' => $primary,
61
            ]
62
        );
63
    }
64
}
65