Skip to content

Commit f1fb422

Browse files
bug symfony#61596 [FrameworkBundle] Normalize workflow places separately (KevinVanSonsbeek)
This PR was merged into the 6.4 branch. Discussion ---------- [FrameworkBundle] Normalize workflow places separately | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix symfony#61581 | License | MIT Rewritten the places `beforeNormalization` callback, to normalize the defined places one by one. Rather than asserting behavior based on only the first item in the passed array. This way it is possible to combine places in both the "simplistic" and non simplistic format for 1 workflow. Commits ------- eddc6a6 [FrameworkBundle] Normalize workflow places separately
2 parents 00934e2 + eddc6a6 commit f1fb422

11 files changed

+392
-18
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -473,27 +473,16 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode): void
473473
throw new InvalidConfigurationException('The "places" option must be an array in workflow configuration.');
474474
}
475475

476-
// It's an indexed array of shape ['place1', 'place2']
477-
if (isset($places[0]) && \is_string($places[0])) {
478-
return array_map(function (string $place) {
479-
return ['name' => $place];
480-
}, $places);
481-
}
482-
483-
// It's an indexed array, we let the validation occur
484-
if (isset($places[0]) && \is_array($places[0])) {
485-
return $places;
486-
}
487-
488-
foreach ($places as $name => $place) {
489-
if (\is_array($place) && \array_key_exists('name', $place)) {
490-
continue;
476+
$normalizedPlaces = [];
477+
foreach ($places as $key => $value) {
478+
if (!\is_array($value)) {
479+
$value = ['name' => $value];
491480
}
492-
$place['name'] = $name;
493-
$places[$name] = $place;
481+
$value['name'] ??= $key;
482+
$normalizedPlaces[] = $value;
494483
}
495484

496-
return array_values($places);
485+
return $normalizedPlaces;
497486
})
498487
->end()
499488
->isRequired()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTestCase;
4+
5+
$container->loadFromExtension('framework', [
6+
'annotations' => false,
7+
'http_method_override' => false,
8+
'handle_all_throwables' => true,
9+
'php_errors' => ['log' => true],
10+
'workflows' => [
11+
'article' => [
12+
'type' => 'workflow',
13+
'supports' => [
14+
FrameworkExtensionTestCase::class,
15+
],
16+
'initial_marking' => ['draft'],
17+
'metadata' => [
18+
'title' => 'article workflow',
19+
'description' => 'workflow for articles',
20+
],
21+
'places' => [
22+
'draft' => [
23+
'metadata' => [
24+
'foo' => 'bar',
25+
],
26+
],
27+
'wait_for_journalist',
28+
'approved_by_journalist' => [
29+
'name' => 'approved_by_journalist',
30+
],
31+
'wait_for_spellchecker',
32+
'approved_by_spellchecker',
33+
'published',
34+
],
35+
'transitions' => [
36+
'request_review' => [
37+
'from' => 'draft',
38+
'to' => ['wait_for_journalist', 'wait_for_spellchecker'],
39+
],
40+
'journalist_approval' => [
41+
'from' => 'wait_for_journalist',
42+
'to' => 'approved_by_journalist',
43+
],
44+
'spellchecker_approval' => [
45+
'from' => 'wait_for_spellchecker',
46+
'to' => 'approved_by_spellchecker',
47+
],
48+
'publish' => [
49+
'from' => ['approved_by_journalist', 'approved_by_spellchecker'],
50+
'to' => 'published',
51+
],
52+
],
53+
],
54+
],
55+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTestCase;
4+
5+
$container->loadFromExtension('framework', [
6+
'annotations' => false,
7+
'http_method_override' => false,
8+
'handle_all_throwables' => true,
9+
'php_errors' => ['log' => true],
10+
'workflows' => [
11+
'article' => [
12+
'type' => 'workflow',
13+
'supports' => [
14+
FrameworkExtensionTestCase::class,
15+
],
16+
'initial_marking' => ['draft'],
17+
'metadata' => [
18+
'title' => 'article workflow',
19+
'description' => 'workflow for articles',
20+
],
21+
'places' => [
22+
'draft',
23+
'wait_for_journalist' => [
24+
'metadata' => [
25+
'description' => 'The article is awaiting approval of an authorized journalist.',
26+
],
27+
],
28+
'approved_by_journalist' => [
29+
'name' => 'approved_by_journalist',
30+
],
31+
'wait_for_spellchecker',
32+
'approved_by_spellchecker',
33+
'published',
34+
],
35+
'transitions' => [
36+
'request_review' => [
37+
'from' => 'draft',
38+
'to' => ['wait_for_journalist', 'wait_for_spellchecker'],
39+
],
40+
'journalist_approval' => [
41+
'from' => 'wait_for_journalist',
42+
'to' => 'approved_by_journalist',
43+
],
44+
'spellchecker_approval' => [
45+
'from' => 'wait_for_spellchecker',
46+
'to' => 'approved_by_spellchecker',
47+
],
48+
'publish' => [
49+
'from' => ['approved_by_journalist', 'approved_by_spellchecker'],
50+
'to' => 'published',
51+
],
52+
],
53+
],
54+
],
55+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns:framework="http://symfony.com/schema/dic/symfony"
4+
xmlns="http://symfony.com/schema/dic/services"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"
7+
>
8+
<framework:config http-method-override="false" handle-all-throwables="true">
9+
<framework:annotations enabled="false"/>
10+
<framework:php-errors log="true"/>
11+
<framework:workflow name="article" type="workflow">
12+
<framework:audit-trail enabled="true"/>
13+
<framework:initial-marking>draft</framework:initial-marking>
14+
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTestCase</framework:support>
15+
<framework:place name="draft">
16+
<framework:metadata>
17+
<framework:foo>bar</framework:foo>
18+
</framework:metadata>
19+
</framework:place>
20+
<framework:place>wait_for_journalist</framework:place>
21+
<framework:place name="approved_by_journalist"/>
22+
<framework:place>wait_for_spellchecker</framework:place>
23+
<framework:place>approved_by_spellchecker</framework:place>
24+
<framework:place>published</framework:place>
25+
<framework:transition name="request_review">
26+
<framework:from>draft</framework:from>
27+
<framework:to>wait_for_journalist</framework:to>
28+
<framework:to>wait_for_spellchecker</framework:to>
29+
</framework:transition>
30+
<framework:transition name="journalist_approval">
31+
<framework:from>wait_for_journalist</framework:from>
32+
<framework:to>approved_by_journalist</framework:to>
33+
</framework:transition>
34+
<framework:transition name="spellchecker_approval">
35+
<framework:from>wait_for_spellchecker</framework:from>
36+
<framework:to>approved_by_spellchecker</framework:to>
37+
</framework:transition>
38+
<framework:transition name="publish">
39+
<framework:from>approved_by_journalist</framework:from>
40+
<framework:from>approved_by_spellchecker</framework:from>
41+
<framework:to>published</framework:to>
42+
</framework:transition>
43+
<framework:metadata>
44+
<framework:title>article workflow</framework:title>
45+
<framework:description>workflow for articles</framework:description>
46+
</framework:metadata>
47+
</framework:workflow>
48+
</framework:config>
49+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns:framework="http://symfony.com/schema/dic/symfony"
4+
xmlns="http://symfony.com/schema/dic/services"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"
7+
>
8+
<framework:config http-method-override="false" handle-all-throwables="true">
9+
<framework:annotations enabled="false"/>
10+
<framework:php-errors log="true"/>
11+
<framework:workflow name="article" type="workflow">
12+
<framework:audit-trail enabled="true"/>
13+
<framework:initial-marking>draft</framework:initial-marking>
14+
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTestCase</framework:support>
15+
<framework:place>draft</framework:place>
16+
<framework:place name="wait_for_journalist">
17+
<framework:metadata>
18+
<framework:description>The article is awaiting approval of an authorized journalist.</framework:description>
19+
</framework:metadata>
20+
</framework:place>
21+
<framework:place name="approved_by_journalist"/>
22+
<framework:place>wait_for_spellchecker</framework:place>
23+
<framework:place>approved_by_spellchecker</framework:place>
24+
<framework:place>published</framework:place>
25+
<framework:transition name="request_review">
26+
<framework:from>draft</framework:from>
27+
<framework:to>wait_for_journalist</framework:to>
28+
<framework:to>wait_for_spellchecker</framework:to>
29+
</framework:transition>
30+
<framework:transition name="journalist_approval">
31+
<framework:from>wait_for_journalist</framework:from>
32+
<framework:to>approved_by_journalist</framework:to>
33+
</framework:transition>
34+
<framework:transition name="spellchecker_approval">
35+
<framework:from>wait_for_spellchecker</framework:from>
36+
<framework:to>approved_by_spellchecker</framework:to>
37+
</framework:transition>
38+
<framework:transition name="publish">
39+
<framework:from>approved_by_journalist</framework:from>
40+
<framework:from>approved_by_spellchecker</framework:from>
41+
<framework:to>published</framework:to>
42+
</framework:transition>
43+
<framework:metadata>
44+
<framework:title>article workflow</framework:title>
45+
<framework:description>workflow for articles</framework:description>
46+
</framework:metadata>
47+
</framework:workflow>
48+
</framework:config>
49+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
framework:
2+
annotations: false
3+
http_method_override: false
4+
handle_all_throwables: true
5+
php_errors:
6+
log: true
7+
workflows:
8+
article:
9+
type: workflow
10+
supports:
11+
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTestCase
12+
initial_marking: [ draft ]
13+
metadata:
14+
title: article workflow
15+
description: workflow for articles
16+
places:
17+
draft:
18+
metadata:
19+
foo: bar
20+
wait_for_journalist: ~
21+
approved_by_journalist: ~
22+
wait_for_spellchecker: ~
23+
approved_by_spellchecker: ~
24+
published: ~
25+
transitions:
26+
request_review:
27+
from: [ draft ]
28+
to: [ wait_for_journalist, wait_for_spellchecker ]
29+
journalist_approval:
30+
from: [ wait_for_journalist ]
31+
to: [ approved_by_journalist ]
32+
spellchecker_approval:
33+
from: [ wait_for_spellchecker ]
34+
to: [ approved_by_spellchecker ]
35+
publish:
36+
from: [ approved_by_journalist, approved_by_spellchecker ]
37+
to: [ published ]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
framework:
2+
annotations: false
3+
http_method_override: false
4+
handle_all_throwables: true
5+
php_errors:
6+
log: true
7+
workflows:
8+
article:
9+
type: workflow
10+
supports:
11+
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTestCase
12+
initial_marking: [ draft ]
13+
metadata:
14+
title: article workflow
15+
description: workflow for articles
16+
places:
17+
- draft:
18+
metadata:
19+
foo: bar
20+
- wait_for_journalist
21+
- approved_by_journalist
22+
- wait_for_spellchecker
23+
- approved_by_spellchecker
24+
- published
25+
transitions:
26+
request_review:
27+
from: [ draft ]
28+
to: [ wait_for_journalist, wait_for_spellchecker ]
29+
journalist_approval:
30+
from: [ wait_for_journalist ]
31+
to: [ approved_by_journalist ]
32+
spellchecker_approval:
33+
from: [ wait_for_spellchecker ]
34+
to: [ approved_by_spellchecker ]
35+
publish:
36+
from: [ approved_by_journalist, approved_by_spellchecker ]
37+
to: [ published ]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
framework:
2+
annotations: false
3+
http_method_override: false
4+
handle_all_throwables: true
5+
php_errors:
6+
log: true
7+
workflows:
8+
article:
9+
type: workflow
10+
supports:
11+
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTestCase
12+
initial_marking: [ draft ]
13+
metadata:
14+
title: article workflow
15+
description: workflow for articles
16+
places:
17+
draft: ~
18+
wait_for_journalist:
19+
metadata:
20+
description: The article is awaiting approval of an authorized journalist.
21+
approved_by_journalist: ~
22+
wait_for_spellchecker: ~
23+
approved_by_spellchecker: ~
24+
published: ~
25+
transitions:
26+
request_review:
27+
from: [ draft ]
28+
to: [ wait_for_journalist, wait_for_spellchecker ]
29+
journalist_approval:
30+
from: [ wait_for_journalist ]
31+
to: [ approved_by_journalist ]
32+
spellchecker_approval:
33+
from: [ wait_for_spellchecker ]
34+
to: [ approved_by_spellchecker ]
35+
publish:
36+
from: [ approved_by_journalist, approved_by_spellchecker ]
37+
to: [ published ]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
framework:
2+
annotations: false
3+
http_method_override: false
4+
handle_all_throwables: true
5+
php_errors:
6+
log: true
7+
workflows:
8+
article:
9+
type: workflow
10+
supports:
11+
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTestCase
12+
initial_marking: [ draft ]
13+
metadata:
14+
title: article workflow
15+
description: workflow for articles
16+
places:
17+
- draft
18+
- wait_for_journalist:
19+
metadata:
20+
description: The article is awaiting approval of an authorized journalist.
21+
- approved_by_journalist
22+
- wait_for_spellchecker
23+
- approved_by_spellchecker
24+
- published
25+
transitions:
26+
request_review:
27+
from: [ draft ]
28+
to: [ wait_for_journalist, wait_for_spellchecker ]
29+
journalist_approval:
30+
from: [ wait_for_journalist ]
31+
to: [ approved_by_journalist ]
32+
spellchecker_approval:
33+
from: [ wait_for_spellchecker ]
34+
to: [ approved_by_spellchecker ]
35+
publish:
36+
from: [ approved_by_journalist, approved_by_spellchecker ]
37+
to: [ published ]

0 commit comments

Comments
 (0)