Skip to content

Conversation

@epitre
Copy link
Contributor

@epitre epitre commented Jul 9, 2020

There's also a default context for the initial marking event.

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #37421
License MIT
Doc PR symfony/symfony-docs#13947

This time, I need context in the events, because, sometimes, the transition is automatic and sometimes, it is manual. I want to be able to make the difference. I figured using the context for that is a good idea. I hope you do too :)

By the way, I believe it also fixes #37421 . I took @pluk77 request to be able to differentiate an initial marking by having a default context in that case

@epitre
Copy link
Contributor Author

epitre commented Jul 9, 2020

appveyor is not happy but I believe it has nothing to do with me. Does it ?

@epitre epitre force-pushed the eventWithContext branch 2 times, most recently from ee4d388 to 348cb02 Compare July 9, 2020 11:07
@epitre epitre changed the title Added Context to Workflow Event [Workflow] Added Context to Workflow Event Jul 9, 2020
class Workflow implements WorkflowInterface
{
public const DISABLE_ANNOUNCE_EVENT = 'workflow_disable_announce_event';
public const DEFAULT_INITIAL_CONTEXT = ['initial' => true];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you made this an associative array and not an indexed one?
public const DEFAULT_INITIAL_CONTEXT = ['initial'];

I see in one of your tests you did use an indexed array as $context.

Are yuo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this way, you can do :
if ($context['initial']??false)

@lyrixx lyrixx added the Workflow label Jul 9, 2020
Copy link
Member

@lyrixx lyrixx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR but I already rejected in the past

@epitre
Copy link
Contributor Author

epitre commented Jul 9, 2020

Thanks for your PR but I already rejected in the past

O_O Does it mean you are rejecting this one ?

What I want, is to be able to differentiate transitions that will be done automatically from others that will be done manually.
If not with the context, how do you suggest to do that ?

@epitre epitre force-pushed the eventWithContext branch from 348cb02 to 6ece94a Compare July 9, 2020 14:06
@epitre
Copy link
Contributor Author

epitre commented Jul 9, 2020

Thanks for your PR but I already rejected in the past

I found an old PR and realized the TransitionEvent knows the context ^^

I'll use this event, then. But I really don't understand why the other events do not deserve to know the context ^^

@lyrixx
Copy link
Member

lyrixx commented Jul 9, 2020

Oups, I write the comment but I forgot to remove it 👍

I'm against to put the context in the guard event but for other event I guess this is fine 👍

O_O Does it mean you are rejecting this one ?

nope, it's OK 👍

Sorry for my bad comment

@epitre epitre force-pushed the eventWithContext branch from 6ece94a to f53d995 Compare July 9, 2020 15:09
@epitre
Copy link
Contributor Author

epitre commented Jul 9, 2020

Oups, I write the comment but I forgot to remove it +1

I'm against to put the context in the guard event but for other event I guess this is fine +1

O_O Does it mean you are rejecting this one ?

nope, it's OK +1

Sorry for my bad comment

Great ! So, GuardEvent is not aware of the context anymore. I simplified TransitionEvent. And TransitionEvent is still the only event which can change the context.

@epitre epitre force-pushed the eventWithContext branch 3 times, most recently from 7756024 to 2b1651c Compare July 9, 2020 15:23
@nicolas-grekas nicolas-grekas added this to the next milestone Jul 9, 2020
foreach ($transition->getTos() as $place) {
$this->dispatcher->dispatch($event, sprintf('workflow.%s.entered.%s', $this->name, $place));
}
} elseif (!empty($this->definition->getInitialPlaces())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not related to the current PR. Could you revert it? thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without that, the DEFAULT_INITIAL_CONTEXT makes no sense.

it's a little far fetched, but I believe adding this context enhancement is a good moment to add this default context

Unless you don't want a DEFAULT_INITIAL_CONTEXT ?

There's also a default context for the initial marking event.
@epitre epitre force-pushed the eventWithContext branch from 2b1651c to bfe07dd Compare July 9, 2020 22:09
@epitre
Copy link
Contributor Author

epitre commented Jul 20, 2020

@lyrixx up !

@lyrixx
Copy link
Member

lyrixx commented Aug 12, 2020

I'm gonna merge your PR, but I also gonna tweak 2/3 things

Thanks for your work and your patience

@lyrixx
Copy link
Member

lyrixx commented Aug 12, 2020

Thank you @epitre.

@lyrixx lyrixx merged commit 25095d8 into symfony:master Aug 12, 2020
fabpot added a commit that referenced this pull request Aug 12, 2020
This PR was merged into the 5.2-dev branch.

Discussion
----------

[Workflow] Simplify code + Updated README.md

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #37539 (cleaning previous PR)
| License       | MIT
| Doc PR        |

Commits
-------

3268bdb [Workflow] Simplify code + Updated README.md
@epitre
Copy link
Contributor Author

epitre commented Aug 12, 2020

@lyrixx Thank you :)

Could you link me the changes you make, just to be informed, please ?

@lyrixx
Copy link
Member

lyrixx commented Aug 12, 2020

Just above: #37813

@philepsybo
Copy link

philepsybo commented Sep 22, 2025

Oups, I write the comment but I forgot to remove it 👍

I'm against to put the context in the guard event but for other event I guess this is fine 👍

O_O Does it mean you are rejecting this one ?

nope, it's OK 👍

Sorry for my bad comment

I know this is a suuuper old issue but i would be interested to know the reasoning why the context should not be included in GuardEvents. If a transition can be requested by a user that is hidden behind some permission while the system should always be able to apply it if triggered by internal logic, it feels quite unintuitive to do this via TransitionEvents (at least for me). If i have a guard that prevents users from applying transitions they are not permitted to apply, i'd find it intuitive to have the option to convey some flag the guard so it knows "check, this is Dev explicitly telling me that this is an internal thing and i don't have to be afraid about the logged in user".
Maybe I am misinterpreting the intended semantics of GuardEvents and this would be an abuse of the concept.

@lyrixx
Copy link
Member

lyrixx commented Oct 1, 2025

I think a subject's transition should only be blocked via its own properties or behaviours. Not by something related to the context. This avoids scattering bits of data between the subject and the context.

Therefore, you should attach what you need to the subject itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Workflow initial_marking is optional and entered event on initial_marking is not dispatched

7 participants