Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 085171f

Browse filesBrowse files
committed
bug #20795 [FrameworkBundle] Allow multiple transitions with the same name (Padam87)
This PR was merged into the 3.2 branch. Discussion ---------- [FrameworkBundle] Allow multiple transitions with the same name | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20794 | License | MIT | Doc PR | - Commits ------- 7c86e16 [FrameworkBundle] Allow multiple transactions with the same name
2 parents a3788e7 + 7c86e16 commit 085171f
Copy full SHA for 085171f

File tree

6 files changed

+177
-4
lines changed
Filter options

6 files changed

+177
-4
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+23-1Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,33 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
296296
->end()
297297
->end()
298298
->arrayNode('transitions')
299-
->useAttributeAsKey('name')
299+
->beforeNormalization()
300+
->always()
301+
->then(function ($transitions) {
302+
// It's an indexed array, we let the validation occurs
303+
if (isset($transitions[0])) {
304+
return $transitions;
305+
}
306+
307+
foreach ($transitions as $name => $transition) {
308+
if (array_key_exists('name', $transition)) {
309+
continue;
310+
}
311+
$transition['name'] = $name;
312+
$transitions[$name] = $transition;
313+
}
314+
315+
return $transitions;
316+
})
317+
->end()
300318
->isRequired()
301319
->requiresAtLeastOneElement()
302320
->prototype('array')
303321
->children()
322+
->scalarNode('name')
323+
->isRequired()
324+
->cannotBeEmpty()
325+
->end()
304326
->arrayNode('from')
305327
->beforeNormalization()
306328
->ifString()

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,13 @@ private function registerWorkflowConfiguration(array $workflows, ContainerBuilde
408408
$type = $workflow['type'];
409409

410410
$transitions = array();
411-
foreach ($workflow['transitions'] as $transitionName => $transition) {
411+
foreach ($workflow['transitions'] as $transition) {
412412
if ($type === 'workflow') {
413-
$transitions[] = new Definition(Workflow\Transition::class, array($transitionName, $transition['from'], $transition['to']));
413+
$transitions[] = new Definition(Workflow\Transition::class, array($transition['name'], $transition['from'], $transition['to']));
414414
} elseif ($type === 'state_machine') {
415415
foreach ($transition['from'] as $from) {
416416
foreach ($transition['to'] as $to) {
417-
$transitions[] = new Definition(Workflow\Transition::class, array($transitionName, $from, $to));
417+
$transitions[] = new Definition(Workflow\Transition::class, array($transition['name'], $from, $to));
418418
}
419419
}
420420
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest;
4+
5+
$container->loadFromExtension('framework', array(
6+
'workflows' => array(
7+
'article' => array(
8+
'type' => 'workflow',
9+
'marking_store' => array(
10+
'type' => 'multiple_state',
11+
),
12+
'supports' => array(
13+
FrameworkExtensionTest::class,
14+
),
15+
'initial_place' => 'draft',
16+
'places' => array(
17+
'draft',
18+
'wait_for_journalist',
19+
'approved_by_journalist',
20+
'wait_for_spellchecker',
21+
'approved_by_spellchecker',
22+
'published',
23+
),
24+
'transitions' => array(
25+
'request_review' => array(
26+
'from' => 'draft',
27+
'to' => array('wait_for_journalist', 'wait_for_spellchecker'),
28+
),
29+
'journalist_approval' => array(
30+
'from' => 'wait_for_journalist',
31+
'to' => 'approved_by_journalist',
32+
),
33+
'spellchecker_approval' => array(
34+
'from' => 'wait_for_spellchecker',
35+
'to' => 'approved_by_spellchecker',
36+
),
37+
'publish' => array(
38+
'from' => array('approved_by_journalist', 'approved_by_spellchecker'),
39+
'to' => 'published',
40+
),
41+
'publish_editor_in_chief' => array(
42+
'name' => 'publish',
43+
'from' => 'draft',
44+
'to' => 'published',
45+
),
46+
),
47+
),
48+
),
49+
));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config>
10+
<framework:workflow name="article" type="workflow" initial-place="draft">
11+
<framework:marking-store type="multiple_state">
12+
<framework:argument>a</framework:argument>
13+
<framework:argument>a</framework:argument>
14+
</framework:marking-store>
15+
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
16+
<framework:place>draft</framework:place>
17+
<framework:place>wait_for_journalist</framework:place>
18+
<framework:place>approved_by_journalist</framework:place>
19+
<framework:place>wait_for_spellchecker</framework:place>
20+
<framework:place>approved_by_spellchecker</framework:place>
21+
<framework:place>published</framework:place>
22+
<framework:transition name="request_review">
23+
<framework:from>draft</framework:from>
24+
<framework:to>wait_for_journalist</framework:to>
25+
<framework:to>wait_for_spellchecker</framework:to>
26+
</framework:transition>
27+
<framework:transition name="journalist_approval">
28+
<framework:from>wait_for_journalist</framework:from>
29+
<framework:to>approved_by_journalist</framework:to>
30+
</framework:transition>
31+
<framework:transition name="spellchecker_approval">
32+
<framework:from>wait_for_spellchecker</framework:from>
33+
<framework:to>approved_by_spellchecker</framework:to>
34+
</framework:transition>
35+
<framework:transition name="publish">
36+
<framework:from>approved_by_journalist</framework:from>
37+
<framework:from>approved_by_spellchecker</framework:from>
38+
<framework:to>published</framework:to>
39+
</framework:transition>
40+
<framework:transition name="publish">
41+
<framework:from>draft</framework:from>
42+
<framework:to>published</framework:to>
43+
</framework:transition>
44+
</framework:workflow>
45+
</framework:config>
46+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
framework:
2+
workflows:
3+
article:
4+
type: workflow
5+
marking_store:
6+
type: multiple_state
7+
supports:
8+
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
9+
initial_place: draft
10+
places:
11+
- draft
12+
- wait_for_journalist
13+
- approved_by_journalist
14+
- wait_for_spellchecker
15+
- approved_by_spellchecker
16+
- published
17+
transitions:
18+
request_review:
19+
from: [draft]
20+
to: [wait_for_journalist, wait_for_spellchecker]
21+
journalist_approval:
22+
from: [wait_for_journalist]
23+
to: [approved_by_journalist]
24+
spellchecker_approval:
25+
from: [wait_for_spellchecker]
26+
to: [approved_by_spellchecker]
27+
publish:
28+
from: [approved_by_journalist, approved_by_spellchecker]
29+
to: [published]
30+
publish_editor_in_chief:
31+
name: publish
32+
from: [draft]
33+
to: [published]

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,29 @@ public function testWorkflowCannotHaveBothArgumentsAndService()
190190
$this->createContainerFromFile('workflow_with_arguments_and_service');
191191
}
192192

193+
public function testWorkflowMultipleTransitionsWithSameName()
194+
{
195+
$container = $this->createContainerFromFile('workflow_with_multiple_transitions_with_same_name');
196+
197+
$this->assertTrue($container->hasDefinition('workflow.article', 'Workflow is registered as a service'));
198+
$this->assertTrue($container->hasDefinition('workflow.article.definition', 'Workflow definition is registered as a service'));
199+
200+
$workflowDefinition = $container->getDefinition('workflow.article.definition');
201+
202+
$transitions = $workflowDefinition->getArgument(1);
203+
204+
$this->assertCount(5, $transitions);
205+
206+
$this->assertSame('request_review', $transitions[0]->getArgument(0));
207+
$this->assertSame('journalist_approval', $transitions[1]->getArgument(0));
208+
$this->assertSame('spellchecker_approval', $transitions[2]->getArgument(0));
209+
$this->assertSame('publish', $transitions[3]->getArgument(0));
210+
$this->assertSame('publish', $transitions[4]->getArgument(0));
211+
212+
$this->assertSame(array('approved_by_journalist', 'approved_by_spellchecker'), $transitions[3]->getArgument(1));
213+
$this->assertSame(array('draft'), $transitions[4]->getArgument(1));
214+
}
215+
193216
public function testRouter()
194217
{
195218
$container = $this->createContainerFromFile('full');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.