I'm trying to plug into order transitions in order to send my order to a custom fulfillment system.

I have a transition called "send_to_fulfillment", and order states "reviewing" and "sent_to_fulfillment".

I'm hooking into the commerce_order.send_to_fulfillment.pre_transition event. What I can't figure out is how to cancel the transition if the process fails. I can certainly just throw an exception and let the site die, but I'd prefer to be able to elegantly stop the transition and inform the user of the error.

Any tips? I've tried WorkflowTransitionEvent::stopPropagation which didn't do it, and I can't seem to find it documented anywhere.

1 Answer 1


We don't have a "cancel" or "reverse" feature right now, but it would be worth a feature request in the State Machine queue. The main thing you / we'll need to overcome is what to do in the event a transition in progress has already saved data, triggered 3rd party services, etc. Presumably, there are certain things that should prevent a transition from being reversed (e.g. I've refunded a payment card and therefore must move the order to a canceled or at least unpaid state). However, other things may fall somewhere in the middle ... be allowable and not prevent reversal.

Lisa had a great idea, too, in that you could define the reverse transition explicitly yourself and trigger it in the event that you had a failure condition in your active transition. That would allow you to encode your own logic for checking / reversing transition side effects.

  • 1
    Thanks for the response Ryan. I hadn't really considered the complications and structured my application a bit differently where this isn't required. I did create an issue on the project, if anyone finds this that is where any discussion will probably be in the future: drupal.org/project/state_machine/issues/3016752
    – Pez
    Commented Dec 20, 2018 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.