You are here

public function NotificationInformation::getPreviousState in Content Moderation Notifications 8.3

Gets the from/previous state of the entity.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The moderated entity.

Return value

\Drupal\workflows\StateInterface The current state of the entity.

Overrides NotificationInformationInterface::getPreviousState

File

src/NotificationInformation.php, line 53

Class

NotificationInformation
Service for notification related questions about the moderated entity.

Namespace

Drupal\content_moderation_notifications

Code

public function getPreviousState(ContentEntityInterface $entity) {
  $previous_state = FALSE;
  $workflow = $this
    ->getWorkflow($entity);
  if (isset($entity->last_revision)) {
    $previous_state = $workflow
      ->getTypePlugin()
      ->getState($entity->last_revision->moderation_state->value);
  }
  if (!$previous_state) {
    $previous_state = $workflow
      ->getTypePlugin()
      ->getInitialState($entity);
  }
  return $previous_state;
}