public StateTransitionValidation::getValidTransitions(ContentEntityInterface $entity, AccountInterface $user)
Gets a list of transitions that are legal for this user on this entity.
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\ModerationStateTransition[] The list of transitions that are legal for this user on this entity.
Overrides StateTransitionValidationInterface::getValidTransitions
File
- core/modules/content_moderation/src/StateTransitionValidation.php, line 114
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 19 20 | public function getValidTransitions(ContentEntityInterface $entity , AccountInterface $user ) { $bundle = $this ->loadBundleEntity( $entity ->getEntityType()->getBundleEntityType(), $entity ->bundle()); /** @var \Drupal\content_moderation\Entity\ModerationState $current_state */ $current_state = $entity ->moderation_state->entity; $current_state_id = $current_state ? $current_state ->id() : $bundle ->getThirdPartySetting( 'content_moderation' , 'default_moderation_state' ); // Determine the states that are legal on this bundle. $legal_bundle_states = $bundle ->getThirdPartySetting( 'content_moderation' , 'allowed_moderation_states' , []); // Legal transitions include those that are possible from the current state, // filtered by those whose target is legal on this bundle and that the // user has access to execute. $transitions = array_filter ( $this ->getTransitionsFrom( $current_state_id ), function (ModerationStateTransition $transition ) use ( $legal_bundle_states , $user ) { return in_array( $transition ->getToState(), $legal_bundle_states , TRUE) && $user ->hasPermission( 'use ' . $transition ->id() . ' transition' ); }); return $transitions ; } |
Please login to continue.