public function StateTransitionValidation::getValidTransitions in Drupal 10
Same name and namespace in other branches
- 8 core/modules/content_moderation/src/StateTransitionValidation.php \Drupal\content_moderation\StateTransitionValidation::getValidTransitions()
- 9 core/modules/content_moderation/src/StateTransitionValidation.php \Drupal\content_moderation\StateTransitionValidation::getValidTransitions()
File
- core/
modules/ content_moderation/ src/ StateTransitionValidation.php, line 43
Class
- StateTransitionValidation
- Validates whether a certain state transition is allowed.
Namespace
Drupal\content_moderationCode
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());
});
}