8000 feature #30468 [Workflow] Added support for many inital places (lyrixx) · symfony/symfony@98045b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 98045b1

Browse files
committed
feature #30468 [Workflow] Added support for many inital places (lyrixx)
This PR was merged into the 4.3-dev branch. Discussion ---------- [Workflow] Added support for many inital places | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #30080 | License | MIT | Doc PR | Commits ------- 1af1bf2 Added support for many inital places
2 parents 522594a + 1af1bf2 commit 98045b1

37 files changed

+250
-45
lines changed

UPGRADE-4.3.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,27 @@ Security
127127
}
128128
```
129129

130+
Workflow
131+
--------
132+
133+
* `initial_place` is deprecated in favour of `initial_places`.
134+
135+
Before:
136+
```yaml
137+
framework:
138+
workflows:
139+
article:
140+
initial_place: draft
141+
```
142+
143+
After:
144+
```yaml
145+
framework:
146+
workflows:
147+
article:
148+
initial_places: [draft]
149+
```
150+
130151
Yaml
131152
----
132153

UPGRADE-5.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ Workflow
368368
* `SupportStrategyInterface` has been removed, use `WorkflowSupportStrategyInterface` instead.
369369
* `ClassInstanceSupportStrategy` has been removed, use `InstanceOfSupportStrategy` instead.
370370
* `MarkingStoreInterface::setMarking()` has a third argument: `array $context = []`.
371+
* Removed support of `initial_place`. Use `initial_places` instead.
371372

372373
Yaml
373374
----

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

Lines changed: 11 additions & 1 deletion
F42D
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
231231
$workflows = [];
232232
}
233233

234-
if (1 === \count($workflows) && isset($workflows['workflows']) && array_keys($workflows['workflows']) !== range(0, \count($workflows) - 1) && !empty(array_diff(array_keys($workflows['workflows']), ['audit_trail', 'type', 'marking_store', 'supports', 'support_strategy', 'initial_place', 'places', 'transitions']))) {
234+
if (1 === \count($workflows) && isset($workflows['workflows']) && array_keys($workflows['workflows']) !== range(0, \count($workflows) - 1) && !empty(array_diff(array_keys($workflows['workflows']), ['audit_trail', 'type', 'marking_store', 'supports', 'support_strategy', 'initial_places', 'places', 'transitions']))) {
235235
$workflows = $workflows['workflows'];
236236
}
237237

@@ -258,6 +258,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
258258
->prototype('array')
259259
->fixXmlConfig('support')
260260
->fixXmlConfig('place')
261+
->fixXmlConfig('initial_place')
261262
->fixXmlConfig('transition')
262263
->children()
263264
->arrayNode('audit_trail')
@@ -312,8 +313,17 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
312313
->cannotBeEmpty()
313314
->end()
314315
->scalarNode('initial_place')
316+
->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3, use the "initial_places" configuration key instead.')
315317
->defaultNull()
316318
->end()
319+
->arrayNode('initial_places')
320+
->beforeNormalization()
321+
->ifTrue(function ($v) { return !\is_array($v); })
322+
->then(function ($v) { return [$v]; })
323+
->end()
324+
->defaultValue([])
325+
->prototype('scalar')->end()
326+
->end()
317327
->arrayNode('places')
318328
->beforeNormalization()
319329
->always()

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,14 +621,14 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
621621

622622
// Create places
623623
$places = array_column($workflow['places'], 'name');
624-
$initialPlace = $workflow['initial_place'] ?? null;
624+
$initialPlaces = $workflow['initial_places'] ?? $workflow['initial_place'] ?? [];
625625

626626
// Create a Definition
627627
$definitionDefinition = new Definition(Workflow\Definition::class);
628628
$definitionDefinition->setPublic(false);
629629
$definitionDefinition->addArgument($places);
630630
$definitionDefinition->addArgument($transitions);
631-
$definitionDefinition->addArgument($initialPlace);
631+
$definitionDefinition->addArgument($initialPlaces);
632632
$definitionDefinition->addArgument($metadataStoreDefinition);
633633

634634
// Create MarkingStore
@@ -676,7 +676,7 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
676676
->addTransitions(array_map(function (Reference $ref) use ($container): Workflow\Transition {
677677
return $container->get((string) $ref);
678678
}, $transitions))
679-
->setInitialPlace($initialPlace)
679+
->setInitialPlace($initialPlaces)
680680
->build()
681681
;
682682
$validator->validate($realDefinition, $name);

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@
270270

271271
<xsd:complexType name="workflow">
272272
<xsd:sequence>
273+
<xsd:element name="initial-place" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
273274
<xsd:element name="marking-store" type="marking_store" minOccurs="0" maxOccurs="1" />
274275
<xsd:element name="support" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
275276
<xsd:element name="place" type="place" minOccurs="0" maxOccurs="unbounded" />
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest;
4+
5+
$container->loadFromExtension('framework', [
6+
'workflows' => [
7+
'legacy' => [
8+
'type' => 'workflow',
9+
'supports' => [
10+
stdClass::class,
11+
],
12+
'initial_place' => 'draft',
13+
'places' => [
14+
'draft',
15+
'published',
16+
],
17+
'transitions' => [
18+
'publish' => [
19+
'from' => 'draft',
20+
'to' => 'published',
21+
],
22+
],
23+
],
24+
],
25+
]);

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_guard_expression.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'supports' => [
1313
FrameworkExtensionTest::class,
1414
],
15-
'initial_place' => 'draft',
15+
'initial_places' => ['draft'],
1616
'places' => [
1717
'draft',
1818
'wait_for_journalist',

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_multiple_transitions_with_same_name.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'supports' => [
1313
FrameworkExtensionTest::class,
1414
],
15-
'initial_place' => 'draft',
15+
'initial_places' => ['draft'],
1616
'places' => [
1717
'draft',
1818
'wait_for_journalist',

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'supports' => [
1313
FrameworkExtensionTest::class,
1414
],
15-
'initial_place' => 'draft',
15+
'initial_places' => ['draft'],
1616
'places' => [
1717
'draft',
1818
'wait_for_journalist',
@@ -47,7 +47,7 @@
4747
'supports' => [
4848
FrameworkExtensionTest::class,
4949
],
50-
'initial_place' => 'start',
50+
'initial_places' => ['start'],
5151
'metadata' => [
5252
'title' => 'workflow title',
5353
],

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'foo' => [
77
'type' => 'workflow',
88
'supports' => ['Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest'],
9-
'initial_place' => 'bar',
9+
'initial_places' => ['bar'],
1010
'places' => ['bar', 'baz'],
1111
'transitions' => [
1212
'bar_baz' => [

0 commit comments

Comments
 (0)
0