|
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\OptionsResolver\OptionsResolver; |
|
9
|
|
|
use Symfony\Component\OptionsResolver\Options; |
|
10
|
|
|
use midcom\datamanager\validation\pattern as validator; |
|
11
|
|
|
use Symfony\Component\Validator\Constraints\Length; |
|
12
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
13
|
|
|
use midcom\datamanager\extension\subscriber\purifySubscriber; |
|
14
|
|
|
use Symfony\Component\Form\AbstractTypeExtension; |
|
15
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Text extension |
|
19
|
|
|
*/ |
|
20
|
|
|
class textExtension extends AbstractTypeExtension |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritdoc} |
|
24
|
|
|
*/ |
|
25
|
135 |
|
public function configureOptions(OptionsResolver $resolver) |
|
26
|
|
|
{ |
|
27
|
1 |
|
$resolver->setDefault('constraints', []); |
|
28
|
1 |
|
helper::add_normalizers($resolver, [ |
|
29
|
|
|
'type_config' => [ |
|
30
|
1 |
|
'forbidden_patterns' => [], |
|
31
|
|
|
'maxlength' => 0, |
|
32
|
|
|
'purify' => false, |
|
33
|
|
|
'purify_config' => [] |
|
34
|
|
|
] |
|
35
|
|
|
]); |
|
36
|
|
|
$resolver->setNormalizer('constraints', function (Options $options, $value) { |
|
37
|
135 |
|
if (!empty($options['type_config']['forbidden_patterns'])) { |
|
38
|
|
|
$value[] = new validator(['forbidden_patterns' => $options['type_config']['forbidden_patterns']]); |
|
39
|
|
|
} |
|
40
|
135 |
|
if (!empty($options['type_config']['maxlength'])) { |
|
41
|
6 |
|
$value[] = new Length(['max' => $options['type_config']['maxlength']]); |
|
42
|
|
|
} |
|
43
|
135 |
|
return $value; |
|
44
|
1 |
|
}); |
|
45
|
1 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritdoc} |
|
49
|
|
|
*/ |
|
50
|
136 |
|
public function buildForm(FormBuilderInterface $builder, array $options) |
|
51
|
|
|
{ |
|
52
|
136 |
|
if (!empty($options['type_config']['purify'])) { |
|
53
|
|
|
$builder->addEventSubscriber(new purifySubscriber($options['type_config']['purify_config'])); |
|
54
|
|
|
} |
|
55
|
136 |
|
} |
|
56
|
|
|
|
|
57
|
1 |
|
public static function getExtendedTypes() : iterable |
|
58
|
|
|
{ |
|
59
|
1 |
|
return [TextType::class]; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|