Passed
Push — master ( 4ffbc4...bfa0fa )
by Andreas
25:06
created

textareaExtension::getExtendedTypes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright CONTENT CONTROL GmbH, http://www.contentcontrol-berlin.de
4
 */
5
6
namespace midcom\datamanager\extension;
7
8
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
9
use Symfony\Component\OptionsResolver\OptionsResolver;
10
use Symfony\Component\OptionsResolver\Options;
11
use Symfony\Component\Form\FormView;
12
use Symfony\Component\Form\FormInterface;
13
use Symfony\Component\Form\AbstractTypeExtension;
14
15
/**
16
 * Textarea extension
17
 */
18
class textareaExtension extends AbstractTypeExtension
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23 106
    public function configureOptions(OptionsResolver $resolver)
24
    {
25 1
        $map_attr = function (Options $options, $value) {
26 106
            if ($value === null) {
27
                $value = [];
28
            }
29 106
            $value['rows'] = $options['widget_config']['height'];
30 106
            $value['cols'] = $options['widget_config']['width'];
31
32 106
            return $value;
33 1
        };
34 1
        $resolver->setDefault('attr', $map_attr);
35
36 1
        helper::add_normalizers($resolver, [
37
            'widget_config' => [
38 1
                'height' => 6,
39
                'width' => 50
40
            ],
41
            'type_config' => [
42 1
                'output_mode' => 'html',
43 1
                'specialchars_quotes' => ENT_QUOTES,
44 1
                'specialchars_charset' => 'UTF-8',
45
                'forbidden_patterns' => [],
46 1
                'maxlength' => 0,
47
                'purify' => false,
48
                'purify_config' => []
49
            ]
50
        ]);
51 1
    }
52
53 105
    public function finishView(FormView $view, FormInterface $form, array $options)
54
    {
55 105
        $view->vars['output_mode'] = $options['type_config']['output_mode'];
56 105
    }
57
58 1
    public static function getExtendedTypes() : iterable
59
    {
60 1
        return [TextareaType::class];
61
    }
62
}
63