You are here

public function NotificationInformation::getNotifications in Content Moderation Notifications 8.2

Same name and namespace in other branches
  1. 8.3 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

array An array containing the entity and the notifications list.

Overrides NotificationInformationInterface::getNotifications

File

src/NotificationInformation.php, line 82

Class

NotificationInformation
Service for notification related questions about the moderated entity.

Namespace

Drupal\content_moderation_notifications

Code

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

    // Find out if we have a config entity that contains this transition.
    $query = \Drupal::entityQuery('content_moderation_notification')
      ->condition('workflow', $workflow
      ->id())
      ->condition('status', 1)
      ->condition('transitions.' . $transition
      ->id(), $transition
      ->id());
    $notification_ids = $query
      ->execute();
    $notifications['notifications'] = !empty($notification_ids) ? $this->entityTypeManager
      ->getStorage('content_moderation_notification')
      ->loadMultiple($notification_ids) : [];
  }
  return $notifications;
}