You are here

public function NotificationInformation::getTransition in Content Moderation Notifications 8.3

Same name and namespace in other branches
  1. 8.2 src/NotificationInformation.php \Drupal\content_moderation_notifications\NotificationInformation::getTransition()

Checks for the current transition of the moderated entity.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity we may be moderating.

Return value

\Drupal\workflows\TransitionInterface|bool The transition object if the entity is moderated FALSE otherwise.

Overrides NotificationInformationInterface::getTransition

1 call to NotificationInformation::getTransition()
NotificationInformation::getNotifications in src/NotificationInformation.php
Gets the list of notification based on the current transition.

File

src/NotificationInformation.php, line 79

Class

NotificationInformation
Service for notification related questions about the moderated entity.

Namespace

Drupal\content_moderation_notifications

Code

public function getTransition(ContentEntityInterface $entity) {
  $transition = FALSE;
  if ($workflow = $this
    ->getWorkflow($entity)) {
    $current_state = $entity->moderation_state->value;
    $previous_state = $this
      ->getPreviousState($entity)
      ->id();
    try {
      $transition = $workflow
        ->getTypePlugin()
        ->getTransitionFromStateToState($previous_state, $current_state);
    } catch (\InvalidArgumentException $e) {

      // There is no available transition. Fall through to return FALSE.
    }
  }
  return $transition;
}