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 f9897cc

Browse filesBrowse files
committed
[Workflow] Added 'workflow_marked_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 83a0aa3 commit f9897cc
Copy full SHA for f9897cc

File tree

3 files changed

+43
-2
lines changed
Filter options

3 files changed

+43
-2
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_marked_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
+32-2Lines changed: 32 additions & 2 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_marked_places', array($this, 'getMarkedPlaces')),
3637
);
3738
}
3839

@@ -63,9 +64,38 @@ public function getEnabledTransitions($subject, $name = null)
6364
return $this->workflowRegistry->get($subject, $name)->getEnabledTransitions($subject);
6465
}
6566

66-
public function hasMarkedPlace($object, $place, $name = null)
67+
/**
68+
* Returns true if the place is marked.
69+
*
70+
* @param object $subject A subject
71+
* @param string $transitionName A transition
72+
* @param string $name A workflow name
73+
*
74+
* @return bool true if the transition is enabled
75+
*/
76+
public function hasMarkedPlace($subject, $place, $name = null)
6777
{
68-
return $this->workflowRegistry->get($object, $name)->getMarking($object)->has($place);
78+
return $this->workflowRegistry->get($subject, $name)->getMarking($subject)->has($place);
79+
}
80+
81+
/**
82+
* Returns all places.
83+
*
84+
* @param object $subject A subject
85+
* @param string $placesNameOnly If true, returns only places name. If false returns the raw representation
86+
* @param string $name A workflow name
87+
*
88+
* @return string[]|int[]
89+
*/
90+
public function getMarkedPlaces($subject, $placesNameOnly = true, $name = null)
91+
{
92+
$places = $this->workflowRegistry->get($subject, $name)->getMarking($subject)->getPlaces();
93+
94+
if ($placesNameOnly) {
95+
return array_keys($places);
96+
}
97+
98+
return $places;
6999
}
70100

71101
public function getName()

‎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.