1 | <?php |
||
23 | class FormContractor implements FormContractorInterface |
||
24 | { |
||
25 | /** |
||
26 | * @var FormFactoryInterface |
||
27 | */ |
||
28 | protected $formFactory; |
||
29 | |||
30 | /** |
||
31 | * @param FormFactoryInterface $formFactory |
||
32 | */ |
||
33 | public function __construct(FormFactoryInterface $formFactory) |
||
37 | |||
38 | /** |
||
39 | * The method defines the correct default settings for the provided FieldDescription |
||
40 | * |
||
41 | * {@inheritDoc} |
||
42 | * |
||
43 | * @throws \RuntimeException if the $fieldDescription does not specify a type. |
||
44 | */ |
||
45 | public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription) |
||
82 | |||
83 | /** |
||
84 | * @return FormFactoryInterface |
||
85 | */ |
||
86 | public function getFormFactory() |
||
90 | |||
91 | /** |
||
92 | * {@inheritDoc} |
||
93 | */ |
||
94 | public function getFormBuilder($name, array $options = array()) |
||
95 | { |
||
96 | return $this->getFormFactory()->createNamedBuilder($name, 'form', null, $options); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * {@inheritDoc} |
||
101 | * |
||
102 | * @throws \LogicException if a sonata_type_model field does not have a |
||
103 | * target model configured. |
||
104 | */ |
||
105 | public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription) |
||
106 | { |
||
107 | $options = array(); |
||
108 | $options['sonata_field_description'] = $fieldDescription; |
||
109 | |||
110 | switch ($type) { |
||
111 | case 'Sonata\DoctrinePHPCRAdminBundle\Form\Type\TreeModelType': |
||
112 | case 'doctrine_phpcr_odm_tree': |
||
113 | $options['class'] = $fieldDescription->getTargetEntity(); |
||
114 | $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager(); |
||
115 | |||
116 | break; |
||
117 | case 'Sonata\AdminBundle\Form\Type\Modeltype': |
||
118 | case 'sonata_type_model': |
||
119 | case 'Sonata\AdminBundle\Form\Type\ModelTypeList': |
||
120 | case 'sonata_type_model_list': |
||
121 | if (!$fieldDescription->getTargetEntity()) { |
||
|
|||
122 | throw new \LogicException(sprintf( |
||
123 | 'The field "%s" in class "%s" does not have a target model defined. ' . |
||
124 | 'Please specify the "targetDocument" attribute in the mapping for this class.', |
||
125 | $fieldDescription->getName(), |
||
126 | $fieldDescription->getAdmin()->getClass() |
||
127 | )); |
||
128 | } |
||
129 | |||
130 | $options['class'] = $fieldDescription->getTargetEntity(); |
||
131 | $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager(); |
||
132 | |||
133 | break; |
||
134 | case 'Sonata\AdminBundle\Form\Type\AdminType': |
||
135 | case 'sonata_type_admin': |
||
136 | if (!$fieldDescription->getAssociationAdmin()) { |
||
137 | throw $this->getAssociationAdminException($fieldDescription); |
||
138 | } |
||
139 | |||
140 | $options['data_class'] = $fieldDescription->getAssociationAdmin()->getClass(); |
||
141 | $fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin')); |
||
142 | |||
143 | break; |
||
144 | case 'Sonata\CoreBundle\Form\Type\CollectionType': |
||
145 | case 'sonata_type_collection': |
||
146 | if (!$fieldDescription->getAssociationAdmin()) { |
||
147 | throw $this->getAssociationAdminException($fieldDescription); |
||
148 | } |
||
149 | |||
150 | $options['type'] = 'sonata_type_admin'; |
||
151 | $options['modifiable'] = true; |
||
152 | $options['type_options'] = array( |
||
153 | 'sonata_field_description' => $fieldDescription, |
||
154 | 'data_class' => $fieldDescription->getAssociationAdmin()->getClass() |
||
155 | ); |
||
156 | |||
157 | break; |
||
158 | } |
||
159 | |||
160 | return $options; |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * @param FieldDescriptionInterface $fieldDescription |
||
165 | * |
||
166 | * @return \LogicException |
||
167 | */ |
||
168 | protected function getAssociationAdminException(FieldDescriptionInterface $fieldDescription) |
||
182 | } |
||
183 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: