public function GroupContentInMyGroupActivityContext::getRecipients in Open Social 10.1.x
Same name and namespace in other branches
- 8.9 modules/custom/activity_basics/src/Plugin/ActivityContext/GroupContentInMyGroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupContentInMyGroupActivityContext::getRecipients()
- 8.4 modules/custom/activity_basics/src/Plugin/ActivityContext/GroupContentInMyGroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupContentInMyGroupActivityContext::getRecipients()
- 8.5 modules/custom/activity_basics/src/Plugin/ActivityContext/GroupContentInMyGroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupContentInMyGroupActivityContext::getRecipients()
- 8.6 modules/custom/activity_basics/src/Plugin/ActivityContext/GroupContentInMyGroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupContentInMyGroupActivityContext::getRecipients()
- 8.7 modules/custom/activity_basics/src/Plugin/ActivityContext/GroupContentInMyGroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupContentInMyGroupActivityContext::getRecipients()
- 8.8 modules/custom/activity_basics/src/Plugin/ActivityContext/GroupContentInMyGroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupContentInMyGroupActivityContext::getRecipients()
- 10.3.x modules/custom/activity_basics/src/Plugin/ActivityContext/GroupContentInMyGroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupContentInMyGroupActivityContext::getRecipients()
- 10.0.x modules/custom/activity_basics/src/Plugin/ActivityContext/GroupContentInMyGroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupContentInMyGroupActivityContext::getRecipients()
- 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.
Parameters
array $data: The data.
int $last_id: The last ID.
int $limit: The limit.
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.
Overrides ActivityContextBase::getRecipients
File
- modules/
custom/ activity_basics/ src/ Plugin/ ActivityContext/ GroupContentInMyGroupActivityContext.php, line 80
Class
- GroupContentInMyGroupActivityContext
- Provides a 'GroupContentInMyGroupActivityContext' activity context.
Namespace
Drupal\activity_basics\Plugin\ActivityContextCode
public function getRecipients(array $data, $last_uid, $limit) {
$recipients = [];
if (!empty($data['related_object'])) {
$referenced_entity = $this->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;
}