Passed
Pull Request — master (#204)
by
unknown
23:41
created

textareaExtension   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 39
ccs 18
cts 19
cp 0.9474
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A finishView() 0 3 1
A configureOptions() 0 22 4
A getExtendedTypes() 0 3 1
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 100
    public function configureOptions(OptionsResolver $resolver)
24
    {
25
        $map_attr = function (Options $options, $value) {
26 100
            if ($value === null) {
27
                $value = [];
28
            }
29 100
            $value['rows'] = !empty($options['widget_config']['height']) ? $options['widget_config']['height'] : 6;
30 100
            $value['cols'] = !empty($options['widget_config']['width']) ? $options['widget_config']['width'] : 50;
31
32 100
            return $value;
33 1
        };
34 1
        $resolver->setDefault('attr', $map_attr);
35
36 1
        helper::add_normalizers($resolver, [
37
            'type_config' => [
38 1
                'output_mode' => 'html',
39 1
                'specialchars_quotes' => ENT_QUOTES,
40 1
                'specialchars_charset' => 'UTF-8',
41
                'forbidden_patterns' => [],
42 1
                'maxlength' => 0,
43
                'purify' => false,
44
                'purify_config' => []
45
            ]
46
        ]);
47 1
    }
48
49 99
    public function finishView(FormView $view, FormInterface $form, array $options)
50
    {
51 99
        $view->vars['output_mode'] = $options['type_config']['output_mode'];
52 99
    }
53
54 1
    public static function getExtendedTypes() : iterable
55
    {
56 1
        return [TextareaType::class];
57
    }
58
}
59