You are here

public function StateTransitionValidation::isTransitionValid in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/content_moderation/src/StateTransitionValidation.php \Drupal\content_moderation\StateTransitionValidation::isTransitionValid()

Checks if a transition between two states if valid for the given user.

Parameters

\Drupal\workflows\WorkflowInterface $workflow: The workflow entity.

\Drupal\workflows\StateInterface $original_state: The original workflow state.

\Drupal\workflows\StateInterface $new_state: The new workflow state.

\Drupal\Core\Session\AccountInterface $user: The user to validate.

\Drupal\Core\Entity\ContentEntityInterface $entity: (optional) The entity to be transitioned. Omitting this parameter is deprecated and will be required in Drupal 9.0.0.

Return value

bool Returns TRUE if transition is valid, otherwise FALSE.

Overrides StateTransitionValidationInterface::isTransitionValid

File

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

Class

StateTransitionValidation
Validates whether a certain state transition is allowed.

Namespace

Drupal\content_moderation

Code

public function isTransitionValid(WorkflowInterface $workflow, StateInterface $original_state, StateInterface $new_state, AccountInterface $user, ContentEntityInterface $entity = NULL) {
  if ($entity === NULL) {
    @trigger_error(sprintf('Omitting the $entity parameter from %s is deprecated and will be required in Drupal 9.0.0.', __METHOD__), E_USER_DEPRECATED);
  }
  $transition = $workflow
    ->getTypePlugin()
    ->getTransitionFromStateToState($original_state
    ->id(), $new_state
    ->id());
  return $user
    ->hasPermission('use ' . $workflow
    ->id() . ' transition ' . $transition
    ->id());
}