function StateTransitionValidation::getValidTransitions

Same name in other branches
  1. 9 core/modules/content_moderation/src/StateTransitionValidation.php \Drupal\content_moderation\StateTransitionValidation::getValidTransitions()
  2. 10 core/modules/content_moderation/src/StateTransitionValidation.php \Drupal\content_moderation\StateTransitionValidation::getValidTransitions()
  3. 11.x core/modules/content_moderation/src/StateTransitionValidation.php \Drupal\content_moderation\StateTransitionValidation::getValidTransitions()

Overrides StateTransitionValidationInterface::getValidTransitions

File

core/modules/content_moderation/src/StateTransitionValidation.php, line 43

Class

StateTransitionValidation
Validates whether a certain state transition is allowed.

Namespace

Drupal\content_moderation

Code

public function getValidTransitions(ContentEntityInterface $entity, AccountInterface $user) {
    $workflow = $this->moderationInfo
        ->getWorkflowForEntity($entity);
    $current_state = $entity->moderation_state->value ? $workflow->getTypePlugin()
        ->getState($entity->moderation_state->value) : $workflow->getTypePlugin()
        ->getInitialState($entity);
    return array_filter($current_state->getTransitions(), function (Transition $transition) use ($workflow, $user) {
        return $user->hasPermission('use ' . $workflow->id() . ' transition ' . $transition->id());
    });
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.