StateTransitionValidation::getValidTransitionTargets

public StateTransitionValidation::getValidTransitionTargets(ContentEntityInterface $entity, AccountInterface $user)

Gets a list of states a user may transition an entity to.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to be transitioned.

\Drupal\Core\Session\AccountInterface $user: The account that wants to perform a transition.

Return value

\Drupal\content_moderation\Entity\ModerationState[] Returns an array of States to which the specified user may transition the entity.

Overrides StateTransitionValidationInterface::getValidTransitionTargets

File

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

Class

StateTransitionValidation
Validates whether a certain state transition is allowed.

Namespace

Drupal\content_moderation

Code

public function getValidTransitionTargets(ContentEntityInterface $entity, AccountInterface $user) {
  $bundle = $this->loadBundleEntity($entity->getEntityType()->getBundleEntityType(), $entity->bundle());

  $states_for_bundle = $bundle->getThirdPartySetting('content_moderation', 'allowed_moderation_states', []);

  /** @var \Drupal\content_moderation\Entity\ModerationState $current_state */
  $current_state = $entity->moderation_state->entity;

  $all_transitions = $this->getPossibleTransitions();
  $destination_ids = $all_transitions[$current_state->id()];

  $destination_ids = array_intersect($states_for_bundle, $destination_ids);
  $destinations = $this->entityTypeManager->getStorage('moderation_state')->loadMultiple($destination_ids);

  return array_filter($destinations, function(ModerationStateInterface $destination_state) use ($current_state, $user) {
    return $this->userMayTransition($current_state, $destination_state, $user);
  });
}
doc_Drupal
2016-10-29 09:44:18
Comments
Leave a Comment

Please login to continue.