Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Using custom workflows in Commerce 2.x, mglaman and I found that when transitioning to the same state, event subscribers do not fire as they should. Only happens when the 'from' and 'to' are the same value.
Use case: A "Print Order" button that would fire a PDF printer and not change the state of the order.
The field formatter displays the transition but the transition does not fire an event.
Proposed resolution
Allow a transition to fire if the source and destination state are the same
Remaining tasks
- Write test
- Fix bug
User interface changes
None. Actually fixes the user interface
Comment | File | Size | Author |
---|---|---|---|
#9 | detector.png | 10.34 KB | zaporylie |
Comments
Comment #2
mglamanComment #3
mglamanSo I talked with bojanz. The real bug here is that transitions are allowed (or recognized) when there is no state value change. I do like the workaround of a transition being available to basically re-run a process... but that isn't quite how this should work.
We need to fix the formatter to, or transition validation, to consider this kind of setup and ignore them.
Comment #4
alexandersluiter CreditAttribution: alexandersluiter commentedI guess that makes sense as far as keeping the "State Machine" a "State Machine". I will have to change my workflows file to reflect not allow non-state-change transitions then.
Is there a way to hook into the fields that it outputs and place another button in there without hooking into the state machine itself?
Comment #5
bojanz CreditAttribution: bojanz at Centarro commentedRetitling.
Comment #7
bojanz CreditAttribution: bojanz at Centarro commentedAdded validation.
Comment #9
zaporylie...4 years later 😅
Sorry for commenting on this, probably a long forgotten&fixed issue but I'm still failing to understand the reasoning as to why transition between the same state is not allowed. And I've been redirected here to search for that answer from #3058874: Allow same From/To state but cant find any clear answer,
All definitions of State Machine I know allow transitions between the same state (as a special case of transition to another state). The key features of State machine are:
- it has limited number of states
- it can be in only one state at the time
- it has defined transitions on how to reach one state from another
Some definitions will say that state machine is just like this direct graph. See the following explanation from Cornell University website:
The definition given on Wikipedia says that "the change from one state to another is called a transition" but at the same times shows plenty of examples how transitions are allowed with from/to states being the same. This is also how the State Machines concept was explained to me back at the University.
In my head another state in this context shouldn't be interpreted as different. It is more to tell that transition requires 2 states - before and after - but doesn't limit it to before and after being actually different states.
That being said one of the popular examples of the State Machine is binary light switch with brightness control. The light can only be in 2 states: on or off but some additional (brightness) transitions are allowed.
Off can only transition to On
On can transition to Off
On can transition to On (brightness down, until off)
On can transition to On (brightness up, until 100%)
In my opinion, support for transitions between the same state should be allowed.