From 3fb92ca8982c7073daf58aaa09408117d54f6463 Mon Sep 17 00:00:00 2001 From: Bert Hekman Date: Wed, 26 Nov 2025 14:15:06 +0100 Subject: [PATCH] [FrameworkBundle] Allow backed enum to be used in initial_marking workflow configuration --- .../DependencyInjection/Configuration.php | 13 ++++++++++++- .../Tests/DependencyInjection/ConfigurationTest.php | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index e8e11d071be92..c3f3b16c7732e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -463,8 +463,19 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode): void ->cannotBeEmpty() ->end() ->arrayNode('initial_marking') - ->acceptAndWrap(['string']) + ->acceptAndWrap(['backed-enum', 'string']) ->defaultValue([]) + ->beforeNormalization() + ->ifArray() + ->then(static function ($markings) { + $normalizedMarkings = []; + foreach ($markings as $marking) { + $normalizedMarkings[] = $marking instanceof \BackedEnum ? $marking->value : $marking; + } + + return $normalizedMarkings; + }) + ->end() ->prototype('scalar')->end() ->end() ->arrayNode('events_to_dispatch', 'event_to_dispatch') diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index e921b09d8eade..c68b805b71ac8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -711,6 +711,7 @@ public function testWorkflowEnumArcsNormalization() 'enum' => [ 'supports' => [self::class], 'places' => Places::cases(), + 'initial_marking' => Places::A, 'transitions' => [ [ 'name' => 'one', @@ -728,6 +729,8 @@ public function testWorkflowEnumArcsNormalization() ], ]]); + $this->assertSame(['a'], $config['workflows']['workflows']['enum']['initial_marking']); + $transitions = $config['workflows']['workflows']['enum']['transitions']; $this->assertSame('one', $transitions[0]['name']);