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

textareaExtension::configureOptions()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4.0072

Importance

Changes 0
Metric Value
cc 4
eloc 16
nc 1
nop 1
dl 0
loc 22
ccs 12
cts 13
cp 0.9231
crap 4.0072
rs 9.7333
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 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