Skip to content

Commit 21c101f

Browse files
bug #62515 [FrameworkBundle] Allow backed enum to be used in initial_marking workflow configuration (DemonTPx)
This PR was squashed before being merged into the 7.4 branch. Discussion ---------- [FrameworkBundle] Allow backed enum to be used in initial_marking workflow configuration | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT I've tried using workflows with an enum, following this article: https://symfony.com/blog/new-in-symfony-7-4-misc-features-part-2#enum-support-in-workflows The `initial_marking` configuration did not support it yet with this error: ``` Invalid type for path "framework.workflows.workflows.comment.initial_marking.0". Expected "scalar", but got "App\Entity\CommentState". ``` This change seems to fix it! Commits ------- 3fb92ca8982 [FrameworkBundle] Allow backed enum to be used in initial_marking workflow configuration
2 parents 3c62a34 + db3a028 commit 21c101f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

DependencyInjection/Configuration.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,19 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode): void
463463
->cannotBeEmpty()
464464
->end()
465465
->arrayNode('initial_marking')
466-
->acceptAndWrap(['string'])
466+
->acceptAndWrap(['backed-enum', 'string'])
467467
->defaultValue([])
468+
->beforeNormalization()
469+
->ifArray()
470+
->then(static function ($markings) {
471+
$normalizedMarkings = [];
472+
foreach ($markings as $marking) {
473+
$normalizedMarkings[] = $marking instanceof \BackedEnum ? $marking->value : $marking;
474+
}
475+
476+
return $normalizedMarkings;
477+
})
478+
->end()
468479
->prototype('scalar')->end()
469480
->end()
470481
->arrayNode('events_to_dispatch', 'event_to_dispatch')

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ public function testWorkflowEnumArcsNormalization()
711711
'enum' => [
712712
'supports' => [self::class],
713713
'places' => Places::cases(),
714+
'initial_marking' => Places::A,
714715
'transitions' => [
715716
[
716717
'name' => 'one',
@@ -728,6 +729,8 @@ public function testWorkflowEnumArcsNormalization()
728729
],
729730
]]);
730731

732+
$this->assertSame(['a'], $config['workflows']['workflows']['enum']['initial_marking']);
733+
731734
$transitions = $config['workflows']['workflows']['enum']['transitions'];
732735

733736
$this->assertSame('one', $transitions[0]['name']);

0 commit comments

Comments
 (0)