Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.4 kB
2
Indexable
Never
<?php

use Drupal\workflow\Entity\Workflow;

/**
 * Implements hook_preprocess_html().
 */
function custom_workflow_roles_preprocess_html(&$variables) {
  // List of predefined workflow machine names.
  $workflow_machine_names = ['phase_1', 'phase_2'];

  // Initialize the overall role-to-state mapping array.
  $overall_role_state_mapping = [];

  // Initialize the common roles array.
  $common_roles = [];

  foreach ($workflow_machine_names as $workflow_machine_name) {
    // Load the current workflow.
    $workflow = Workflow::load($workflow_machine_name);

    if ($workflow) {
      // Get all transitions of the current workflow.
      $transitions = $workflow->getTransitions();

      foreach ($transitions as $transition_id => $transition) {
        // Iterate through the roles for this transition.
        foreach ($transition->roles as $role_id => $active) {
          if ($active) {
              // Store the state information for the role.
              if (!isset($common_roles[$role_id])) {
                $common_roles[$role_id] = [];
              }
              $common_roles[$role_id][] = $transition->to_sid;
          }
        }
      }
    }
  }

  // Attach the common roles array to template variables.
  $variables['common_role_state_mapping'] = $common_roles;
  print_r($common_roles);exit;
}