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.
I had assumed that I could change an entity's state like this:
$license->state = 'active';
$license->save();
That appears to work, but I don't know if I'm bypassing things like the transition guards.
I see in the code for Commerce Shipping that there's this:
$transition = $shipment->getState()->getWorkflow()->getTransition('finalize');
$shipment->getState()->applyTransition($transition);
$shipment->save();
Is that correct, or are they both equivalent?
If the latter method is correct and my method is wrong, then the README should document this.
Comments
Comment #2
bojanz CreditAttribution: bojanz commentedNeed to do #3012846: Add StateItem::applyTransitionById() first.
It's generally recommended to apply the transition instead of hardcoding the ID, so that you can allow a different workflow to use a different state for the same transition (placed orders end up in different states, for example)
Comment #4
bojanz CreditAttribution: bojanz commentedDone.