-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
Symfony version(s) affected
6.4
Description
The workflow docs page shows examples in yaml, php and xml format for how to define a workflow: https://symfony.com/doc/current/workflow/dumping-workflows.html
Some of the shown config for the places does not work however.
The config
symfony/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
Line 503 in 83c2aec
| if (isset($places[0]) && \is_string($places[0])) { |
beforeNormalization, where a check is performed on only the first item from the array, to decide how the entire array of places should be mapped.
This can however result in issues if the config uses a mix of "simple" and "complex" place definitions.
Resulting in the following exception if started with a simple place definition, followed by a complex one:
1) Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\XmlFrameworkExtensionTest::testWorkflowWithMixedPlacesConfig
TypeError: Symfony\Bundle\FrameworkBundle\DependencyInjection\Configuration::Symfony\Bundle\FrameworkBundle\DependencyInjection\{closure}(): Argument #1 ($place) must be of type string, array given
Or when first defining a complex place, followed by a simple one, resulting in the following exception:
1) Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\YamlFrameworkExtensionTest::testWorkflowWithMixedPlacesConfig
Symfony\Component\Config\Definition\Exception\InvalidConfigurationException: Unrecognized option "draft" under "framework.workflows.workflows.article.places.0". Available options are "metadata", "name".
How to reproduce
Create a workflow config (regardless of config syntax used) that contains a mix of ways the places are defined.
<framework:config>
<framework:workflow name="article" type="state_machine" initial-marking="start">
<framework:place>draft</framework:place>
<framework:place name="wait_for_approval">
<framework:metadata>
<framework:description>Await approval from editor before publishing is allowed.</framework:description>
</framework:metadata>
</framework:place>
</framework:workflow>
</framework:config>
<!-- or -->
<framework:config>
<framework:workflow name="article" type="state_machine" initial-marking="start">
<framework:place name="draft">
<framework:metadata>
<framework:description>Stage to edit the article without time pressure.</framework:description>
</framework:metadata>
</framework:place>
<framework:place>wait_for_approval<framework:place>
</framework:workflow>
</framework:config>$container->loadFromExtension('framework', [
'workflows' => [
'article' => [
'places' => [
'draft',
'wait_for_journalist' => [
'metadata' => [
'description' => 'The article is awaiting approval of an authorized journalist.'
]
],
],
],
],
]);
// or
$container->loadFromExtension('framework', [
'workflows' => [
'article' => [
'places' => [
'draft' =>[
'metadata' => [
'description' => 'Stage to edit the article without time pressure.'
]
],
'wait_for_journalist'.
],
],
],
]);framework:
workflows:
article:
places:
- draft
- wait_for_journalist:
metadata:
description: The article is awaiting approval of an authorized journalist.
# or
framework:
workflows:
article:
places:
- draft:
metadata:
description: Stage to edit the article without time pressure.
- wait_for_journalistPossible Solution
The callback should probably loop through each item in the array, and then individually check the format for each item to determin how to map them to a valid places config.
Additional Context
No response