1 | <?php |
||
20 | class FormContractor implements FormContractorInterface |
||
21 | { |
||
22 | /** |
||
23 | * @deprecated since version 3.0.4, to be removed in 4.0 |
||
24 | * |
||
25 | * @var FormFactoryInterface |
||
26 | */ |
||
27 | protected $fieldFactory; |
||
28 | |||
29 | /** |
||
30 | * @var FormFactoryInterface |
||
31 | */ |
||
32 | protected $formFactory; |
||
33 | |||
34 | /** |
||
35 | * @param FormFactoryInterface $formFactory |
||
36 | */ |
||
37 | public function __construct(FormFactoryInterface $formFactory) |
||
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription) |
||
46 | { |
||
47 | if ($admin->getModelManager()->hasMetadata($admin->getClass())) { |
||
48 | $metadata = $admin->getModelManager()->getMetadata($admin->getClass()); |
||
49 | |||
50 | // set the default field mapping |
||
51 | if (isset($metadata->fieldMappings[$fieldDescription->getName()])) { |
||
52 | $fieldDescription->setFieldMapping($metadata->fieldMappings[$fieldDescription->getName()]); |
||
53 | } |
||
54 | |||
55 | // set the default association mapping |
||
56 | if (isset($metadata->associationMappings[$fieldDescription->getName()])) { |
||
57 | $fieldDescription->setAssociationMapping($metadata->associationMappings[$fieldDescription->getName()]); |
||
58 | } |
||
59 | } |
||
60 | |||
61 | if (!$fieldDescription->getType()) { |
||
62 | throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin))); |
||
63 | } |
||
64 | |||
65 | $fieldDescription->setAdmin($admin); |
||
66 | $fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'standard')); |
||
67 | |||
68 | if ($this->hasAssociation($fieldDescription) || $fieldDescription->getOption('admin_code')) { |
||
69 | $admin->attachAdminClass($fieldDescription); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @return FormFactoryInterface |
||
75 | */ |
||
76 | public function getFormFactory() |
||
77 | { |
||
78 | return $this->formFactory; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * {@inheritdoc} |
||
83 | */ |
||
84 | public function getFormBuilder($name, array $options = array()) |
||
85 | { |
||
86 | // NEXT_MAJOR: Remove this line when drop Symfony <2.8 support |
||
87 | $formType = method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') |
||
88 | ? 'Symfony\Component\Form\Extension\Core\Type\FormType' : 'form'; |
||
89 | |||
90 | return $this->getFormFactory()->createNamedBuilder($name, $formType, null, $options); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * {@inheritdoc} |
||
95 | */ |
||
96 | public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription) |
||
163 | |||
164 | /** |
||
165 | * @param FieldDescriptionInterface $fieldDescription |
||
166 | * |
||
167 | * @return bool |
||
168 | */ |
||
169 | private function hasAssociation(FieldDescriptionInterface $fieldDescription) |
||
178 | } |
||
179 |