You are here

public function Workflow::getStates in Workflow 8

Gets all states for a given workflow.

Parameters

mixed $all: Indicates to which states to return.

  • TRUE = all, including Creation and Inactive;
  • FALSE = only Active states, not Creation;
  • 'CREATION' = only Active states, including Creation.

bool $reset:

Return value

\Drupal\workflow\Entity\WorkflowState[] An array of WorkflowState objects.

Overrides WorkflowInterface::getStates

4 calls to Workflow::getStates()
Workflow::delete in src/Entity/Workflow.php
Given a wid, delete the workflow and its data.
Workflow::getCreationState in src/Entity/Workflow.php
Gets the initial state for a newly created entity.
Workflow::getTransitions in src/Entity/Workflow.php
Loads all allowed ConfigTransitions for this workflow.
Workflow::isValid in src/Entity/Workflow.php
Validate the workflow. Generate a message if not correct.

File

src/Entity/Workflow.php, line 348

Class

Workflow
Workflow configuration entity to persistently store configuration.

Namespace

Drupal\workflow\Entity

Code

public function getStates($all = FALSE, $reset = FALSE) {
  $wid = $this
    ->id();
  if ($reset) {
    $this->states = $wid ? WorkflowState::loadMultiple([], $wid, $reset) : [];
  }
  elseif ($this->states === NULL) {
    $this->states = $wid ? WorkflowState::loadMultiple([], $wid, $reset) : [];
  }
  elseif ($this->states === []) {
    $this->states = $wid ? WorkflowState::loadMultiple([], $wid, $reset) : [];
  }

  // Do not unset, but add to array - you'll remove global objects otherwise.
  $states = [];
  foreach ($this->states as $state) {
    $id = $state
      ->id();
    if ($all === TRUE) {
      $states[$id] = $state;
    }
    elseif ($all === FALSE && ($state
      ->isActive() && !$state
      ->isCreationState())) {
      $states[$id] = $state;
    }
    elseif ($all == 'CREATION' && ($state
      ->isActive() || $state
      ->isCreationState())) {
      $states[$id] = $state;
    }
    else {

      // Do not add state.
    }
  }
  return $states;
}