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 659bd29

Browse filesBrowse files
committed
[Workflow] Added 'workflow_places' twig function
When someone uses a custom MarkingStore, the value in the $subject::marking can be really different from the value inside Marking::getPlaces(). This occurs, for example, when the value stored in the subject is a bit mask. So it's always safer to get the places names from the marking, and so with this new function.
1 parent 1b63474 commit 659bd29
Copy full SHA for 659bd29

File tree

3 files changed

+23
-0
lines changed
Filter options

3 files changed

+23
-0
lines changed

‎src/Symfony/Bridge/Twig/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* added a `workflow_has_marked_place` function
8+
* added a `workflow_places` function
89

910
3.2.0
1011
-----

‎src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function getFunctions()
3333
new \Twig_SimpleFunction('workflow_can', array($this, 'canTransition')),
3434
new \Twig_SimpleFunction('workflow_transitions', array($this, 'getEnabledTransitions')),
3535
new \Twig_SimpleFunction('workflow_has_marked_place', array($this, 'hasMarkedPlace')),
36+
new \Twig_SimpleFunction('workflow_places', array($this, 'getMarkedPlaces')),
3637
);
3738
}
3839

@@ -51,6 +52,17 @@ public function hasMarkedPlace($object, $place, $name = null)
5152
return $this->workflowRegistry->get($object, $name)->getMarking($object)->has($place);
5253
}
5354

55+
public function getMarkedPlaces($object, $placesNameOnly = true, $name = null)
56+
{
57+
$places = $this->workflowRegistry->get($object, $name)->getMarking($object)->getPlaces();
58+
59+
if ($placesNameOnly) {
60+
return array_keys($places);
61+
}
62+
63+
return $places;
64+
}
65+
5466
public function getName()
5567
{
5668
return 'workflow';

‎src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,14 @@ public function testHasMarkedPlace()
7575
$this->assertTrue($this->extension->hasMarkedPlace($subject, 'waiting_for_payment'));
7676
$this->assertFalse($this->extension->hasMarkedPlace($subject, 'processed'));
7777
}
78+
79+
public function testGetMarkedPlaces()
80+
{
81+
$subject = new \stdClass();
82+
$subject->marking = array();
83+
$subject->marking = array('ordered' => 1, 'waiting_for_payment' => 1);
84+
85+
$this->assertSame(array('ordered', 'waiting_for_payment'), $this->extension->getMarkedPlaces($subject));
86+
$this->assertSame($subject->marking, $this->extension->getMarkedPlaces($subject, false));
87+
}
7888
}

0 commit comments

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