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
Currently there is no easy way to add an event listener that subscribes to all the transition events of all the workflows in the system.
A developer might want to subscribe to all transitions for example to handle default revisions/published status (our case) or to send notifications to the interested users.
Proposed resolution
Fire also a more generic event during the pre and post transition phases.
To keep backwards compatibility, leave in place the previous specific transition event.
Remaining tasks
None.
User interface changes
None.
API changes
No changes really, just added new "state_machine.pre_transition" and "state_machine.post_transition" events.
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#4 | interdiff-2832415-2-4.txt | 2.09 KB | sardara |
#4 | fire_generic_events-2832415-4.patch | 6.1 KB | sardara |
#2 | fire_generic_events-2832415-2.patch | 7.94 KB | sardara |
Comments
Comment #2
sardara CreditAttribution: sardara at Randstad Digital for European Commission and European Union Institutions, Agencies and Bodies commentedComment #3
bojanz CreditAttribution: bojanz commentedMakes sense. Let's remove the $phase from the even though, it's pointless since you always know whether you subscribed to pre_transition or post_transition.
Comment #4
sardara CreditAttribution: sardara at Randstad Digital for European Commission and European Union Institutions, Agencies and Bodies commentedYou are completely right, with the current implementation it doesn't make sense. I'm attaching the fix already that removes the $phase.
Just to be sure, do you think it's better to remove the $phase or to launch a single event (e.g. "state_machine.transition") for both phases?
Comment #5
sardara CreditAttribution: sardara at Randstad Digital for European Commission and European Union Institutions, Agencies and Bodies commentedComment #6
pfrenssenThis looks good to me, went through it with my fine comb but found no complaints :) Thanks!
Comment #7
mitrpaka CreditAttribution: mitrpaka as a volunteer commentedRTBC +1
Currently patch provided in #2894779: Send order receipt email once an order is placed or validated, depending on the workflow used. relies on this.
Comment #8
bojanz CreditAttribution: bojanz commentedGreat job!
Let's also add a workflow-group-specific generic event, to handle the use case mentioned in #2894810: Fire events named after the destination state rather than the transition name (where we know only the end state).
Comment #10
bojanz CreditAttribution: bojanz commentedAdded $workflow_group . $phase events, updated the README. And committed!