You are here

public function WorkflowConfigTransitionFormBase::load in Workflow 8

Create an $entity for every ConfigTransition.

1 call to WorkflowConfigTransitionFormBase::load()
WorkflowConfigTransitionFormBase::buildForm in src/Form/WorkflowConfigTransitionFormBase.php
Form constructor.

File

src/Form/WorkflowConfigTransitionFormBase.php, line 93

Class

WorkflowConfigTransitionFormBase
Defines a class to build a draggable listing of Workflow Config Transitions entities.

Namespace

Drupal\workflow\Form

Code

public function load() {
  $entities = [];
  $entity_type = $this->entitiesKey;
  $workflow = $this->workflow;
  $states = $workflow
    ->getStates($all = 'CREATION');
  if ($states) {

    /** @var \Drupal\workflow\Entity\WorkflowState $from_state */

    /** @var \Drupal\workflow\Entity\WorkflowState $to_state */
    switch ($entity_type) {
      case 'workflow_state':
        foreach ($states as $from_state) {
          $from_sid = $from_state
            ->id();
          $entities[$from_sid] = $from_state;
        }
        break;
      case 'workflow_config_transition':
        foreach ($states as $from_state) {
          $from_sid = $from_state
            ->id();
          foreach ($states as $to_state) {
            $to_sid = $to_state
              ->id();

            // Don't allow transition TO (creation).
            if ($to_state
              ->isCreationState()) {
              continue;
            }

            // Only allow transitions from $from_state.
            if ($to_sid != $from_sid) {

              // continue.
            }

            // Load existing config_transitions. Create if not found.
            $config_transitions = $workflow
              ->getTransitionsByStateId($from_sid, $to_sid);
            if (!($config_transition = reset($config_transitions))) {
              $config_transition = $workflow
                ->createTransition($from_sid, $to_sid);
            }
            $entities[] = $config_transition;
          }
        }
        break;
      default:
        $this
          ->messenger()
          ->addError($this
          ->t('Improper type provided in load method.'));
        $this->logger
          ->notice('Improper type provided in load method.', []);
    }
  }
  return $entities;
}