You are here

public function FollowContentActivityContext::getRecipientsWhoFollowContent in Open Social 8.8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_follow_content/src/Plugin/ActivityContext/FollowContentActivityContext.php \Drupal\social_follow_content\Plugin\ActivityContext\FollowContentActivityContext::getRecipientsWhoFollowContent()
  2. 8 modules/social_features/social_follow_content/src/Plugin/ActivityContext/FollowContentActivityContext.php \Drupal\social_follow_content\Plugin\ActivityContext\FollowContentActivityContext::getRecipientsWhoFollowContent()
  3. 8.2 modules/social_features/social_follow_content/src/Plugin/ActivityContext/FollowContentActivityContext.php \Drupal\social_follow_content\Plugin\ActivityContext\FollowContentActivityContext::getRecipientsWhoFollowContent()
  4. 8.3 modules/social_features/social_follow_content/src/Plugin/ActivityContext/FollowContentActivityContext.php \Drupal\social_follow_content\Plugin\ActivityContext\FollowContentActivityContext::getRecipientsWhoFollowContent()
  5. 8.4 modules/social_features/social_follow_content/src/Plugin/ActivityContext/FollowContentActivityContext.php \Drupal\social_follow_content\Plugin\ActivityContext\FollowContentActivityContext::getRecipientsWhoFollowContent()
  6. 8.5 modules/social_features/social_follow_content/src/Plugin/ActivityContext/FollowContentActivityContext.php \Drupal\social_follow_content\Plugin\ActivityContext\FollowContentActivityContext::getRecipientsWhoFollowContent()
  7. 8.6 modules/social_features/social_follow_content/src/Plugin/ActivityContext/FollowContentActivityContext.php \Drupal\social_follow_content\Plugin\ActivityContext\FollowContentActivityContext::getRecipientsWhoFollowContent()
  8. 8.7 modules/social_features/social_follow_content/src/Plugin/ActivityContext/FollowContentActivityContext.php \Drupal\social_follow_content\Plugin\ActivityContext\FollowContentActivityContext::getRecipientsWhoFollowContent()
  9. 10.3.x modules/social_features/social_follow_content/src/Plugin/ActivityContext/FollowContentActivityContext.php \Drupal\social_follow_content\Plugin\ActivityContext\FollowContentActivityContext::getRecipientsWhoFollowContent()
  10. 10.0.x modules/social_features/social_follow_content/src/Plugin/ActivityContext/FollowContentActivityContext.php \Drupal\social_follow_content\Plugin\ActivityContext\FollowContentActivityContext::getRecipientsWhoFollowContent()
  11. 10.1.x modules/social_features/social_follow_content/src/Plugin/ActivityContext/FollowContentActivityContext.php \Drupal\social_follow_content\Plugin\ActivityContext\FollowContentActivityContext::getRecipientsWhoFollowContent()
  12. 10.2.x modules/social_features/social_follow_content/src/Plugin/ActivityContext/FollowContentActivityContext.php \Drupal\social_follow_content\Plugin\ActivityContext\FollowContentActivityContext::getRecipientsWhoFollowContent()

Returns owner recipient from entity.

Parameters

array $related_entity: The related entity.

array $data: The data.

Return value

array An associative array of recipients, containing the following key-value pairs:

  • target_type: The entity type ID.
  • target_id: The entity ID.
1 call to FollowContentActivityContext::getRecipientsWhoFollowContent()
FollowContentActivityContext::getRecipients in modules/social_features/social_follow_content/src/Plugin/ActivityContext/FollowContentActivityContext.php
Returns a batched list of recipients for this context.

File

modules/social_features/social_follow_content/src/Plugin/ActivityContext/FollowContentActivityContext.php, line 51

Class

FollowContentActivityContext
Provides a 'FollowContentActivityContext' activity context plugin.

Namespace

Drupal\social_follow_content\Plugin\ActivityContext

Code

public function getRecipientsWhoFollowContent(array $related_entity, array $data) {
  $recipients = [];
  $storage = $this->entityTypeManager
    ->getStorage('flagging');
  $flaggings = $storage
    ->loadByProperties([
    'flag_id' => 'follow_content',
    'entity_type' => $related_entity['target_type'],
    'entity_id' => $related_entity['target_id'],
  ]);

  // We don't send notifications to users about their own comments.
  $original_related_object = $data['related_object'][0];
  $storage = $this->entityTypeManager
    ->getStorage($original_related_object['target_type']);
  $original_related_entity = $storage
    ->load($original_related_object['target_id']);
  foreach ($flaggings as $flagging) {

    /* @var $flagging \Drupal\flag\FlaggingInterface */
    $recipient = $flagging
      ->getOwner();

    // It could happen that a notification has been queued but the content or
    // account has since been deleted. In that case we can find no recipient.
    if (!$recipient instanceof UserInterface) {
      break;
    }
    if ($recipient
      ->id() !== $original_related_entity
      ->getOwnerId() && $original_related_entity
      ->access('view', $recipient)) {
      $recipients[] = [
        'target_type' => 'user',
        'target_id' => $recipient
          ->id(),
      ];
    }
  }
  return $recipients;
}