|
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.
|
@@ -339,6 +340,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
|
339 | 340 | ->fixXmlConfig('support')
|
340 | 341 | ->fixXmlConfig('place')
|
341 | 342 | ->fixXmlConfig('transition')
|
| 343 | + ->fixXmlConfig('event_to_dispatch', 'events_to_dispatch') |
342 | 344 | ->children()
|
343 | 345 | ->arrayNode('audit_trail')
|
344 | 346 | ->canBeEnabled()
|
@@ -381,6 +383,33 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
|
381 | 383 | ->defaultValue([])
|
382 | 384 | ->prototype('scalar')->end()
|
383 | 385 | ->end()
|
| 386 | + ->variableNode('events_to_dispatch') |
| 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; |
| 407 | + }) |
| 408 | + ->thenInvalid('The value must be "null" or an array of workflow events (like ["workflow.enter"]).') |
| 409 | + ->end() |
| 410 | + ->info('Select which Transition events should be dispatched for this Workflow') |
| 411 | + ->example(['workflow.enter', 'workflow.transition']) |
| 412 | + ->end() |
384 | 413 | ->arrayNode('places')
|
385 | 414 | ->beforeNormalization()
|
386 | 415 | ->always()
|
@@ -509,6 +538,18 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
|
509 | 538 | })
|
510 | 539 | ->thenInvalid('"supports" or "support_strategy" should be configured.')
|
511 | 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('event_to_dispatch', $values) && null === $values['event_to_dispatch']) { |
| 546 | + $values['events_to_dispatch'] = []; |
| 547 | + unset($values['event_to_dispatch']); |
| 548 | + } |
| 549 | + |
| 550 | + return $values; |
| 551 | + }) |
| 552 | + ->end() |
512 | 553 | ->end()
|
513 | 554 | ->end()
|
514 | 555 | ->end()
|
|
0 commit comments