You are here

private function ModerationStateWidget::getStates in Lightning Scheduler 8

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.

1 call to ModerationStateWidget::getStates()
ModerationStateWidget::formElement in src/Plugin/Field/FieldWidget/ModerationStateWidget.php
Returns the form for a single field widget.

File

src/Plugin/Field/FieldWidget/ModerationStateWidget.php, line 194

Class

ModerationStateWidget
Scheduler extension of Content Moderation's widget.

Namespace

Drupal\lightning_scheduler\Plugin\Field\FieldWidget

Code

private 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;
}