You are here

protected function StateItem::getAllowedStates in State Machine 8

Gets the next allowed states for the given field value.

Parameters

string $value: The field value, representing the state ID.

Return value

\Drupal\state_machine\Plugin\Workflow\WorkflowState[] The allowed states.

2 calls to StateItem::getAllowedStates()
StateItem::getSettableOptions in src/Plugin/Field/FieldType/StateItem.php
Returns an array of settable values with labels for display.
StateItem::isValid in src/Plugin/Field/FieldType/StateItem.php
Gets whether the current state is valid.

File

src/Plugin/Field/FieldType/StateItem.php, line 218

Class

StateItem
Plugin implementation of the 'state' field type.

Namespace

Drupal\state_machine\Plugin\Field\FieldType

Code

protected function getAllowedStates($value) {
  $workflow = $this
    ->getWorkflow();
  if (!$workflow) {

    // The workflow is not known yet, the field is probably being created.
    return [];
  }
  $allowed_states = [];
  if (!empty($value) && ($current_state = $workflow
    ->getState($value))) {
    $allowed_states[$value] = $current_state;
  }
  $transitions = $workflow
    ->getAllowedTransitions($value, $this
    ->getEntity());
  foreach ($transitions as $transition) {
    $state = $transition
      ->getToState();
    $allowed_states[$state
      ->getId()] = $state;
  }
  return $allowed_states;
}