You are here

public function GroupContentInMyGroupActivityContext::getRecipients in Open Social 8.6

Same name and namespace in other branches
  1. 8.9 modules/custom/activity_basics/src/Plugin/ActivityContext/GroupContentInMyGroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupContentInMyGroupActivityContext::getRecipients()
  2. 8.4 modules/custom/activity_basics/src/Plugin/ActivityContext/GroupContentInMyGroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupContentInMyGroupActivityContext::getRecipients()
  3. 8.5 modules/custom/activity_basics/src/Plugin/ActivityContext/GroupContentInMyGroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupContentInMyGroupActivityContext::getRecipients()
  4. 8.7 modules/custom/activity_basics/src/Plugin/ActivityContext/GroupContentInMyGroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupContentInMyGroupActivityContext::getRecipients()
  5. 8.8 modules/custom/activity_basics/src/Plugin/ActivityContext/GroupContentInMyGroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupContentInMyGroupActivityContext::getRecipients()
  6. 10.3.x modules/custom/activity_basics/src/Plugin/ActivityContext/GroupContentInMyGroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupContentInMyGroupActivityContext::getRecipients()
  7. 10.0.x modules/custom/activity_basics/src/Plugin/ActivityContext/GroupContentInMyGroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupContentInMyGroupActivityContext::getRecipients()
  8. 10.1.x modules/custom/activity_basics/src/Plugin/ActivityContext/GroupContentInMyGroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupContentInMyGroupActivityContext::getRecipients()
  9. 10.2.x modules/custom/activity_basics/src/Plugin/ActivityContext/GroupContentInMyGroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupContentInMyGroupActivityContext::getRecipients()

Returns a batched list of recipients for this context.

Format array( array ( id = uid or gip type = "user / group" ) )

Overrides ActivityContextBase::getRecipients

File

modules/custom/activity_basics/src/Plugin/ActivityContext/GroupContentInMyGroupActivityContext.php, line 75

Class

GroupContentInMyGroupActivityContext
Provides a 'GroupContentInMyGroupActivityContext' acitivy context.

Namespace

Drupal\activity_basics\Plugin\ActivityContext

Code

public function getRecipients(array $data, $last_uid, $limit) {
  $recipients = [];
  if (!empty($data['related_object'])) {
    $referenced_entity = ActivityFactory::getActivityRelatedEntity($data);

    /** @var \Drupal\group\Entity\GroupContentInterface $group_content */
    $group_content = $this->entityTypeManager
      ->getStorage('group_content')
      ->load($referenced_entity['target_id']);

    // It could happen that a notification has been queued but the content
    // has since been deleted. In that case we can find no additional
    // recipients.
    if (!$group_content) {
      return $recipients;
    }

    /** @var \Drupal\group\Entity\GroupInterface $group */
    $group = $group_content
      ->getGroup();
    $memberships = $group
      ->getMembers($group
      ->bundle() . '-group_manager');

    // List of managers which shouldn't receive notifications.
    $account_ids = [
      // The current user when he/she is a manager.
      $this->currentUser
        ->id(),
      // New group member with the "Group manager" role.
      $group_content
        ->getEntity()
        ->id(),
    ];

    /** @var \Drupal\group\GroupMembership $membership */
    foreach ($memberships as $membership) {
      if (!in_array($membership
        ->getUser()
        ->id(), $account_ids)) {
        $recipients[] = [
          'target_type' => 'user',
          'target_id' => $membership
            ->getUser()
            ->id(),
        ];
      }
    }
  }
  return $recipients;
}