-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[WORKFLOW] [RFC] Pass context/metadata in the entire workflow process #27925
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
Comments
What about adding |
@lyrixx I am ok for that 👍 |
Right now you you can do it like this: class Entity
{
public function applyTransition(WorkflowInterface $workflow, string $transitionName, array $context)
{
$workflow->apply($this, $transitionName);
$this->context = $context;
}
} This is not perfect, but could do the job |
@lyrixx yes it was my first idea but kind of hack :/ do you think it could be a nice additional feature? |
Interesting PR, thank you for posting it |
@Padam87 The intent is different here. In your case, it was done to control things. |
My intent was exacly the same. :) The ability to pass parameters. #20774 If by control you mean that the parameters were also passed to the can method that is because if passing parameters is enabled, then guards should also have access to them. |
IMHO, this contest should on by used by the marking store, to store more information. |
in my example the context was intended to be passed to the whole workflow, but of course for getting data to set, not validation with the can (guard) |
Hm, I don't know. On one hand it makes sense to allow the dev to deal with this outside of the workflow, on the other that could lead to this: if ($someParam === 'someValue' && $workflow->can($object, 'transition')) {
$worflow->apply($object, 'transition', ['someParam' => $someParam])
} Now the decision is made at 2 places, guard and controller. I don't like that. Anyway, event params would be nice, even if it is just for the |
Hi, I'd like +1 the idea. As for now we are likely to use a wrapper around our actual carton entity with a context property on the wrapper as we don't want to pollute the entity it self. We plan to have a custom marking store that will operate on the carton entity's Far from ideal, but we would like to keep the logic in the workflow guards and transitions as much as possible. PS: yohang/Finite does something similar, but I'd rather use this SF component for the attached utilities. |
+1 for this idea from my side. |
+1 |
Is anyone willing to provide a PR for this feature? |
Did it already. Just needs a touch up, and ready to go if it gets the go ahead. (The PR was for 3.2, and the $context argument name is much better than what I used.) |
+1 Here is an example: Let's take an auction as exemple described in workflow.yaml below. The auction is simple, user can create an auction but only an admin can start the auction. After that, each user can bid only one to an auction. Also, to be able to bid, you must have an active membership. pretty simple business logic.
Thanks to the metadata, I can specify which role is required to start an auction. Fine it as been put in place. |
…ixx) This PR was merged into the 4.3-dev branch. Discussion ---------- [Workflow] Added a context to `Workflow::apply()` | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #27925 (maybe #28253 and #28266) | License | MIT | Doc PR | Commits ------- 7d5b7a3 [Workflow] Added a context to `Workflow::apply()`
#29146 is now merged. You can test it and give me some feedback. Thanks |
@lyrixx do you still need help on this? Do you have any advice on how to test this? |
It's in symfony 4.3 😁 everything works fine. Thanks |
@SulivanDotEu you can handle your use case using custom Security Voter and 'guard' property of transition. Like that: ...
transitions:
start:
guard: "is_granted('ROLE_ADMIN', subject) or is_granted('ROLE_SUPERADMIN', subject)"
from: draft
to: submitted
make_an_offer:
guard: "is_granted('ALLOW_TO_BID', subject)"
from: started
to: started ALLOW_TO_BID - is your custom security voter where you can check if the current user have rights to create a new bid. |
Description
Hi
We are using the workflow component to redesign our internal processing of some business entities.
We are now facing some logic we did not know how to deal with on our code port.
Previously we were doing on our entities status change this logic:
and the setStatus() method is like this
We were storing a statusLog on every status change with the new status, the date of change, the user (blameable) and an optionnal comment => for log/debug/history purpose
But now with the workflow, it is our internal marking store that call the
setStatus()
(mapping of the current place to our internal status because we store an int not a string),and unfortunately we are not able to pass some other metadata.
Feature Request
Discussion on the availability to have a workflow business context to allow the developper to pass some context in the workflow process,
and get this context inside the workflow process, all workflow events and in the workflow marking store logic as well.
Is this a feature that can be usefull for this component? giving some possibility to developpers?
Or maybe developpers are already dealing differently for this kind of purpose?
Obviously we can add an in memory property on the entity for storing the comment and if it is not null, get it for the
addStatusLogRecord()
but this design is not pleasant at all.Many thank for your time and thank you for this component that helps us a lot
The text was updated successfully, but these errors were encountered: