forked from netgen/TagsBundle
/
FormMapper.php
96 lines (90 loc) · 3.53 KB
/
FormMapper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace Netgen\TagsBundle\Core\FieldType\Tags;
use EzSystems\RepositoryForms\Data\FieldDefinitionData;
use EzSystems\RepositoryForms\FieldType\FieldDefinitionFormMapperInterface;
use Netgen\TagsBundle\Form\Type\TagTreeType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Validator\Constraints;
class FormMapper implements FieldDefinitionFormMapperInterface
{
/**
* @var array
*/
protected $availableEditViews = array();
/**
* Sets the available edit views.
*
* @param array $availableEditViews
*/
public function setEditViews(array $availableEditViews)
{
$this->availableEditViews = $availableEditViews;
}
public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data)
{
$editViewChoices = array();
foreach ($this->availableEditViews as $editView) {
$editViewChoices[$editView['name']] = $editView['identifier'];
}
$fieldDefinitionForm
->add(
'subTreeLimit', TagTreeType::class, array(
'property_path' => 'fieldSettings[subTreeLimit]',
'label' => 'field_definition.eztags.settings.subtree_limit',
)
)
->add(
'hideRootTag', CheckboxType::class, array(
'required' => false,
'property_path' => 'fieldSettings[hideRootTag]',
'label' => 'field_definition.eztags.settings.hide_root_tag',
'constraints' => array(
new Constraints\Type(array('type' => 'bool')),
new Constraints\NotNull(),
),
)
)
->add(
'maxTags', IntegerType::class, array(
'required' => false,
'property_path' => 'fieldSettings[maxTags]',
'label' => 'field_definition.eztags.settings.max_tags',
'constraints' => array(
new Constraints\Type(array('type' => 'int')),
new Constraints\NotBlank(),
new Constraints\GreaterThanOrEqual(
array(
'value' => 0,
)
),
),
'empty_data' => 0,
'attr' => array(
'min' => 0,
),
)
)
->add(
'editView', ChoiceType::class, array(
'choices' => $editViewChoices,
'choices_as_values' => true,
'required' => true,
'property_path' => 'fieldSettings[editView]',
'label' => 'field_definition.eztags.settings.edit_view',
'constraints' => array(
new Constraints\Type(array('type' => 'string')),
new Constraints\NotBlank(),
new Constraints\Choice(
array(
'choices' => array_values($editViewChoices),
'strict' => true,
)
),
),
)
);
}
}