|
2 | 2 |
|
3 | 3 | namespace FormBuilderBundle\EventSubscriber; |
4 | 4 |
|
| 5 | +use FormBuilderBundle\Registry\DataInjectionRegistry; |
5 | 6 | use FormBuilderBundle\Validator\Constraints\DynamicMultiFileNotBlank; |
6 | 7 | use FormBuilderBundle\Model\FieldDefinitionInterface; |
7 | 8 | use FormBuilderBundle\Model\FormFieldContainerDefinitionInterface; |
|
25 | 26 |
|
26 | 27 | class FormBuilderSubscriber implements EventSubscriberInterface |
27 | 28 | { |
28 | | - protected Configuration $configuration; |
29 | | - protected EventDispatcherInterface $eventDispatcher; |
30 | | - protected Dispatcher $dispatcher; |
31 | | - protected FormRegistryInterface $formRegistry; |
32 | | - |
33 | 29 | private array $availableConstraints; |
34 | 30 | private array $availableFormTypes; |
35 | 31 |
|
36 | 32 | public function __construct( |
37 | | - Configuration $configuration, |
38 | | - EventDispatcherInterface $eventDispatcher, |
39 | | - Dispatcher $dispatcher, |
40 | | - FormRegistryInterface $formRegistry |
| 33 | + protected Configuration $configuration, |
| 34 | + protected EventDispatcherInterface $eventDispatcher, |
| 35 | + protected Dispatcher $dispatcher, |
| 36 | + protected FormRegistryInterface $formRegistry, |
| 37 | + protected DataInjectionRegistry $dataInjectionRegistry |
41 | 38 | ) { |
42 | | - $this->configuration = $configuration; |
43 | | - $this->eventDispatcher = $eventDispatcher; |
44 | | - $this->dispatcher = $dispatcher; |
45 | | - $this->formRegistry = $formRegistry; |
46 | 39 | $this->availableConstraints = $this->configuration->getAvailableConstraints(); |
47 | 40 | $this->availableFormTypes = $this->configuration->getConfig('types'); |
48 | 41 | } |
@@ -204,15 +197,19 @@ private function addFormBuilderField(FormFieldDefinitionInterface $field, array |
204 | 197 |
|
205 | 198 | // options enrichment: tweak preferred choice options |
206 | 199 | if (in_array($field->getType(), $this->getChoiceFieldTypes(), true)) { |
207 | | - if (isset($options['multiple']) && $options['multiple'] === false |
208 | | - && isset($options['data']) |
209 | | - && is_array($options['data']) |
210 | | - && !empty($options['data']) |
211 | | - ) { |
| 200 | + if (isset($options['multiple']) && $options['multiple'] === false && array_key_exists('data', $options) && is_array($options['data'])) { |
212 | 201 | $options['data'] = $options['data'][0]; |
213 | 202 | } |
214 | 203 | } |
215 | 204 |
|
| 205 | + if (array_key_exists('dataInjection', $options) && !empty($options['dataInjection'])) { |
| 206 | + $dataInjection = json_decode($options['dataInjection'], true); |
| 207 | + unset($options['dataInjection']); |
| 208 | + if ($this->dataInjectionRegistry->has($dataInjection['injector'])) { |
| 209 | + $options['data'] = $this->dataInjectionRegistry->get($dataInjection['injector'])->parseData($dataInjection['config']); |
| 210 | + } |
| 211 | + } |
| 212 | + |
216 | 213 | // options enrichment: add constraints |
217 | 214 | if (in_array('constraints', $availableOptions)) { |
218 | 215 | $conditionalConstraintData = $this->dispatchConditionalLogicModule('constraints', $conditionalLogicOptions); |
|
0 commit comments