public function FollowTaxonomyActivityContext::getRecipientsWhoFollowTaxonomy in Open Social 10.3.x
Same name and namespace in other branches
- 10.0.x modules/social_features/social_follow_taxonomy/src/Plugin/ActivityContext/FollowTaxonomyActivityContext.php \Drupal\social_follow_taxonomy\Plugin\ActivityContext\FollowTaxonomyActivityContext::getRecipientsWhoFollowTaxonomy()
- 10.1.x modules/social_features/social_follow_taxonomy/src/Plugin/ActivityContext/FollowTaxonomyActivityContext.php \Drupal\social_follow_taxonomy\Plugin\ActivityContext\FollowTaxonomyActivityContext::getRecipientsWhoFollowTaxonomy()
- 10.2.x modules/social_features/social_follow_taxonomy/src/Plugin/ActivityContext/FollowTaxonomyActivityContext.php \Drupal\social_follow_taxonomy\Plugin\ActivityContext\FollowTaxonomyActivityContext::getRecipientsWhoFollowTaxonomy()
Returns recipients from followed taxonomies.
1 call to FollowTaxonomyActivityContext::getRecipientsWhoFollowTaxonomy()
- FollowTaxonomyActivityContext::getRecipients in modules/
social_features/ social_follow_taxonomy/ src/ Plugin/ ActivityContext/ FollowTaxonomyActivityContext.php - Returns a batched list of recipients for this context.
1 method overrides FollowTaxonomyActivityContext::getRecipientsWhoFollowTaxonomy()
- FollowTagActivityContext::getRecipientsWhoFollowTaxonomy in modules/
social_features/ social_follow_taxonomy/ modules/ social_follow_tag/ src/ Plugin/ ActivityContext/ FollowTagActivityContext.php - Returns recipients from followed taxonomies.
File
- modules/
social_features/ social_follow_taxonomy/ src/ Plugin/ ActivityContext/ FollowTaxonomyActivityContext.php, line 141
Class
- FollowTaxonomyActivityContext
- Provides a 'FollowTaxonomyActivityContext' activity context plugin.
Namespace
Drupal\social_follow_taxonomy\Plugin\ActivityContextCode
public function getRecipientsWhoFollowTaxonomy(array $related_entity, array $data) {
$recipients = [];
$entity = $this->entityTypeManager
->getStorage($related_entity['target_type'])
->load($related_entity['target_id']);
if (!empty($entity)) {
$tids = $this
->taxonomyTermsList($entity);
}
if (empty($tids)) {
return [];
}
// Get followers.
$uids = $this->connection
->select('flagging', 'f')
->fields('f', [
'uid',
])
->condition('flag_id', 'follow_term')
->condition('entity_type', 'taxonomy_term')
->condition('entity_id', $tids, 'IN')
->groupBy('uid')
->execute()
->fetchCol();
/** @var \Drupal\user\UserInterface[] $users */
$users = $this->entityTypeManager
->getStorage('user')
->loadMultiple($uids);
foreach ($users as $recipient) {
// 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) {
continue;
}
// Do not send notification for inactive user.
if ($recipient
->isBlocked() || !$recipient
->getLastLoginTime()) {
continue;
}
// We don't send notifications to content creator.
if ($recipient
->id() === $entity
->getOwnerId()) {
continue;
}
// Check if user have access to view node.
if (!$this
->haveAccessToNode($recipient, $entity
->id())) {
continue;
}
$recipients[] = [
'target_type' => 'user',
'target_id' => $recipient
->id(),
];
}
return $recipients;
}