|
34 | 34 | use Symfony\Component\Translation\Translator;
|
35 | 35 | use Symfony\Component\Validator\Validation;
|
36 | 36 | use Symfony\Component\WebLink\HttpHeaderSerializer;
|
| 37 | +use Symfony\Component\Workflow\WorkflowEvents; |
37 | 38 |
|
38 | 39 | /**
|
39 | 40 | * FrameworkExtension configuration structure.
|
@@ -382,21 +383,32 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
|
382 | 383 | ->defaultValue([])
|
383 | 384 | ->prototype('scalar')->end()
|
384 | 385 | ->end()
|
385 |
| - ->arrayNode('dispatched_events') |
386 |
| - ->beforeNormalization() |
387 |
| - ->ifString() |
388 |
| - ->then(function ($v) { |
389 |
| - return [$v]; |
| 386 | + ->variableNode('dispatched_events') |
| 387 | + ->defaultValue(null) |
| 388 | + ->validate() |
| 389 | + ->ifTrue(function ($v) { |
| 390 | + if (null === $v) { |
| 391 | + return false; |
| 392 | + } |
| 393 | + if (!\is_array($v)) { |
| 394 | + return true; |
| 395 | + } |
| 396 | + |
| 397 | + foreach ($v as $value) { |
| 398 | + if (!\is_string($value)) { |
| 399 | + return true; |
| 400 | + } |
| 401 | + if (class_exists(WorkflowEvents::class) && !\in_array($value, WorkflowEvents::ALIASES)) { |
| 402 | + return true; |
| 403 | + } |
| 404 | + } |
| 405 | + |
| 406 | + return false; |
390 | 407 | })
|
| 408 | + ->thenInvalid('The value must be "null" or an array of workflow events (like ["workflow.enter"]).') |
391 | 409 | ->end()
|
392 |
| - // We have to specify a default here as when this config option |
393 |
| - // isn't set the default behaviour of `arrayNode()` is to return an empty |
394 |
| - // array which conflicts with our Definition, and we cannot set a default |
395 |
| - // of `null` for arrayNode()'s |
396 |
| - ->defaultValue(['all']) |
397 |
| - ->prototype('scalar')->end() |
398 | 410 | ->info('Select which Transition events should be dispatched for this Workflow')
|
399 |
| - ->example(['leave', 'completed']) |
| 411 | + ->example(['workflow.enter', 'workflow.transition']) |
400 | 412 | ->end()
|
401 | 413 | ->arrayNode('places')
|
402 | 414 | ->beforeNormalization()
|
@@ -526,6 +538,18 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
|
526 | 538 | })
|
527 | 539 | ->thenInvalid('"supports" or "support_strategy" should be configured.')
|
528 | 540 | ->end()
|
| 541 | + ->beforeNormalization() |
| 542 | + ->always() |
| 543 | + ->then(function ($values) { |
| 544 | + // Special case to deal with XML when the user wants an empty array |
| 545 | + if (\array_key_exists('dispatched_event', $values) && null === $values['dispatched_event']) { |
| 546 | + $values['dispatched_events'] = []; |
| 547 | + unset($values['dispatched_event']); |
| 548 | + } |
| 549 | + |
| 550 | + return $values; |
| 551 | + }) |
| 552 | + ->end() |
529 | 553 | ->end()
|
530 | 554 | ->end()
|
531 | 555 | ->end()
|
|
0 commit comments