public function TransitionManager::getStates in Lightning Workflow 8.2
Same name and namespace in other branches
- 8.3 modules/lightning_scheduler/src/TransitionManager.php \Drupal\lightning_scheduler\TransitionManager::getStates()
 
Returns an array of available workflow states for an entity.
A workflow state is considered "available" if the current user has permission to use or schedule it.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity which has the workflow.
Return value
array An associative array where the keys are the workflow state IDs, and the values are the states' human-readable labels.
File
- modules/
lightning_scheduler/ src/ TransitionManager.php, line 87  
Class
Namespace
Drupal\lightning_schedulerCode
public function getStates(ContentEntityInterface $entity) {
  $states = [];
  $workflow = $this->moderationInformation
    ->getWorkflowForEntity($entity);
  foreach ($workflow
    ->getTypePlugin()
    ->getTransitions() as $transition) {
    $base_permission = $workflow
      ->id() . ' transition ' . $transition
      ->id();
    if ($this->currentUser
      ->hasPermission("schedule {$base_permission}") || $this->currentUser
      ->hasPermission("use {$base_permission}")) {
      $to_state = $transition
        ->to();
      $states[$to_state
        ->id()] = $to_state
        ->label();
    }
  }
  return $states;
}