You are here

public function NotificationInformation::getNotifications in Content Moderation Notifications 8.3

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

Gets the list of notification based on the current transition.

Parameters

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

Return value

\Drupal\content_moderation_notifications\ContentModerationNotificationInterface[] An array containing the notifications list.

Overrides NotificationInformationInterface::getNotifications

File

src/NotificationInformation.php, line 99

Class

NotificationInformation
Service for notification related questions about the moderated entity.

Namespace

Drupal\content_moderation_notifications

Code

public function getNotifications(EntityInterface $entity) {
  $notifications = [];
  if ($this
    ->isModeratedEntity($entity)) {
    $workflow = $this
      ->getWorkflow($entity);
    if ($transition = $this
      ->getTransition($entity)) {

      // Find out if we have a config entity that contains this transition.
      $query = $this->entityTypeManager
        ->getStorage('content_moderation_notification')
        ->getQuery()
        ->condition('workflow', $workflow
        ->id())
        ->condition('status', 1)
        ->condition('transitions.' . $transition
        ->id(), $transition
        ->id());
      $notification_ids = $query
        ->execute();
      $notifications = $this->entityTypeManager
        ->getStorage('content_moderation_notification')
        ->loadMultiple($notification_ids);
    }
  }
  return $notifications;
}