You are here

public function NotificationInformation::getTransition in Content Moderation Notifications 8.2

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

Checks for the current transition of the moderated entity.

Parameters

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

Return value

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 59

Class

NotificationInformation
Service for notification related questions about the moderated entity.

Namespace

Drupal\content_moderation_notifications

Code

public function getTransition(EntityInterface $entity) {
  $transition = FALSE;
  if ($workflow = $this
    ->getWorkflow($entity)) {
    $current_state = $entity->moderation_state->value;
    $previous_state = '';
    if (isset($entity->last_revision)) {
      $previous_state = $entity->last_revision->moderation_state->value;
    }
    if (empty($previous_state)) {
      $previous_state = $workflow
        ->getTypePlugin()
        ->getInitialState($workflow, $entity)
        ->id();
    }
    $transition = $workflow
      ->getTransitionFromStateToState($previous_state, $current_state);
  }
  return $transition;
}