execute action on workflow transition I want to execute PHP script in my custom module, when transition occurs. Workflow is assigned to custom entity. I'm using Drupal's core modules Workflow and Content moderation. How can I do that programmatically?
You can use hook_ENTITY_TYPE_update to achieve this.

/**
 * Implements hook_ENTITY_TYPE_update().
*/

function mymodule_node_update(Drupal\Core\Entity\EntityInterface $entity) {

    //Get the current Moderation state;
    if (isset($entity-&gt;moderation_state) &amp;&amp; isset($entity-&gt;moderation_state-&gt;getValue()[0]['target_id'])) {
        $currentState = $entity-&gt;hasField('moderation_state') ? $entity-&gt;moderation_state-&gt;getValue()[0]['target_id'] : null;
    }
    //Get the original Moderation state;
    if ( isset($entity-&gt;original-&gt;moderation_state ) &amp;&amp; isset($entity-&gt;original-&gt;moderation_state-&gt;getValue()[0]['target_id']) ) {
        $originalState = $entity-&gt;original !== NULL ? $entity-&gt;original-&gt;moderation_state-&gt;getValue()[0]['target_id'] : null;
    }

    #Get the Transition;
    $workflowTransition = rtrim($originalState.'--&gt;'.$currentState);

    switch ($workflowTransition) {
       case 'published--&gt;needs_review':
       case 'draft--&gt;needs_review':
       //Do something.
      break;
       case 'draft--&gt;needs_review':
      //Do something else;
      break;
    }
 }