ImageType::configureOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 1
eloc 13
nc 1
nop 1
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
            'flex' => null,
35
            'searchable' => null,
36
            'align' => null,
37
            'cellAlign' => null,
38
            'sortable' => null,
39
        ));
40
41
        $resolver->setAllowedTypes('attr', 'array');
42
    }
43
44
    /**
45
     * @param mixed             $value
46
     * @param mixed             $object
47
     * @param mixed             $primary
48
     * @param \Twig_Environment $twig
49
     *
50
     * @return mixed
51
     */
52
    public function render($value, $object, $primary, \Twig_Environment $twig)
53
    {
54
        /** dont use twig if no template is provided */
55
        if (null === $this->getOption('template')) {
56
            return $this->getOption('prefix').$value;
57
        }
58
59
        return $this->renderTemplate(
60
            $twig,
61
            $this->getOption('template'),
62
            [
63
                'value'   => $value,
64
                'object'  => $object,
65
                'primary' => $primary,
66
            ]
67
        );
68
    }
69
}
70