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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 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 ); }); } |
Please login to continue.