-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Workflow][Twig] add workflow_has_state function #20781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
* @param array $places | ||
* @param Transition[] $transitions | ||
*/ | ||
protected function recursiveBacktraceTransitions(&$finished, $places, $transitions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not be protected
this is clearly lacking tests. |
I know, I will add tests if you think it is okay to have this in the codebase :) |
de5afa0
to
f85b378
Compare
Are the tests failing because of a fluke ? :S |
$workflow = $this->workflowRegistry->get($object, $name); | ||
$marking = $workflow->getMarking($object); | ||
|
||
return array_key_exists($state, $marking->getPlaces()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return $marking->has($state);
return array_key_exists($state, $marking->getPlaces()); | ||
} | ||
|
||
public function isComplete($object, $state, $name = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the use case for this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cannot determine if a state is completed just because of the active states, this function tracks back and checks.
Use case: http://bootsnipp.com/snippets/featured/form-process-steps
f85b378
to
6708342
Compare
Hello @Padam87 I'm totally ok for the new twig method I really tried to understand what is the Finally, As I'm ok for the first one, you could split this PR into 2 PR to get it merged faster. |
I think I will remove My goal was this: Let's say we have 4 places, A -> B ->C -> D, and we are currently in C. |
This looks like very specific to your use case. And the name is not even good, as what you are actually doing is trying to identify the previous states. |
6708342
to
6bfb447
Compare
6bfb447
to
81592c8
Compare
Hello @Padam87 Could you take time to finish this one? If you can't and if you agree, I can push directly into your fork to finish it. Just tell me ;) |
Oups. Sorry. I did not see you updated the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
(failures are not related)
I have one question: Should it be a test ? ie something like: {% if (subject is workflow_place 'place name') %}
yes
{% endif %} |
yes it should be a test, except that the syntax will be this one: {% if subject is workflow_place('place name') %}
yes
{% endif %} |
though I'm not sure about the naming here. The subject is not the place itself. |
oups, I forgot the {% if subject is workflow_has_place('place name') %}
yes
{% endif %} |
@lyrixx when writing the name for a test, you should avoid using a verb in it, as |
@stof: I agree with you it's weird. but |
@lyrixx the issue is that reading the source code is confusing then, as the workflow is not in the place; the subject is. |
Fair enough. Actually, I have not strong preference here. So I will be ok with almost anything ;) |
Trying to find a good name for this is very challenging. Would it make any sense to call it {% if workflow_has_marked(subject, 'place name') %}
...
{% endif %}
{% if workflow_is_marked(subject, 'place name') %}
...
{% endif %} |
@javiereguiluz Your suggestions look weird when being used as tests as there will be two |
@xabbuh shouldn't be {# weird #}
{% if subject is workflow_in_place('aaa') %}
{# ok? #}
{% if workflow_in_place(subject, 'aaa') %} |
Why do you want to use a function for this? What you are actually doing here is testing for a condition. |
To be honest, I'm not sure. I just consider better to use a function because it makes Twig code easier to understand. Besides, all the current functions are called |
I would also use a function here for consistency and because findingva good name for a test sounds difficul.
… On 22 Dec 2016, at 18:47, Javier Eguiluz ***@***.***> wrote:
To be honest, I'm not sure. I just consider better to use a function because it makes Twig code easier to understand. Besides, all the current functions are called workflow_* so it's mandatory to keep using that to make things easier to learn.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
👍 |
@@ -45,6 +46,14 @@ public function getEnabledTransitions($object, $name = null) | |||
return $this->workflowRegistry->get($object, $name)->getEnabledTransitions($object); | |||
} | |||
|
|||
public function hasPlace($object, $state, $name = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, it's weird to call the variable state
when the twig function, php method call it place
.
Could you update it please?
$workflow = $this->workflowRegistry->get($object, $name); | ||
$marking = $workflow->getMarking($object); | ||
|
||
return $marking->has($state); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All others implementations fit on one line.
return $this->workflowRegistry->get($object, $name)->getMarking()->has($state);
{ | ||
$subject = new \stdClass(); | ||
|
||
$marking = new Marking(array('ordered' => true, 'waiting_for_payment' => true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should be 1
and not true
|
||
$marking = new Marking(array('ordered' => true, 'waiting_for_payment' => true)); | ||
|
||
$workflow = $this->getMock(Workflow::class, array(), array(), '', false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in a previous PR, fab change all occurrences of getMock
to use getMockBuiler...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway, I would use concrete implementation instead of mock.
I will be simpler.
Closing in favor of #20781 |
…unction (Padam87, lyrixx) This PR was merged into the 3.3-dev branch. Discussion ---------- [TwigBridge][Worklow] Added a new workflow_has_place function | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20781 | License | MIT | Doc PR | --- This PR follow up #20781 I also increased the Coverage of the WorkflowExtension and finally I added an extra commit that is not related to clean-up 2 unused properties Commits ------- 108c89d [TwigBridge] Removed unused class property 77f820e [TwigBridge][Workflow] Added more tests on WorkflowExtension efe500d [TwigBridge][Workflow] Fixed code and tests 4d0cc68 [TwigBridge][Workflow] Added workflow_has_place twig function
Use case: I needed to create a wizard like visualization for the status, I think this is common enough to be useful for others too.