Passed
Push — master ( 2275f4...6b55ec )
by Andreas
25:05
created

textareaExtension::configureOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 18
nc 1
nop 1
dl 0
loc 24
ccs 21
cts 21
cp 1
crap 1
rs 9.6666
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 108
    public function configureOptions(OptionsResolver $resolver)
24
    {
25 1
        $map_attr = function (Options $options, $value) {
26 108
            $value ??= [];
27 108
            $value['rows'] = $options['widget_config']['height'];
28 108
            $value['cols'] = $options['widget_config']['width'];
29
30 108
            return $value;
31 1
        };
32 1
        $resolver->setDefault('attr', $map_attr);
33
34 1
        helper::add_normalizers($resolver, [
35 1
            'widget_config' => [
36 1
                'height' => 6,
37 1
                'width' => 50
38 1
            ],
39 1
            'type_config' => [
40 1
                'output_mode' => 'html',
41 1
                'specialchars_quotes' => ENT_QUOTES,
42 1
                'specialchars_charset' => 'UTF-8',
43 1
                'forbidden_patterns' => [],
44 1
                'maxlength' => 0,
45 1
                'purify' => false,
46 1
                'purify_config' => []
47 1
            ]
48 1
        ]);
49
    }
50
51 107
    public function finishView(FormView $view, FormInterface $form, array $options)
52
    {
53 107
        $view->vars['output_mode'] = $options['type_config']['output_mode'];
54
    }
55
56 1
    public static function getExtendedTypes() : iterable
57
    {
58 1
        return [TextareaType::class];
59
    }
60
}
61