FollowTagActivityContext.php in Open Social 10.2.x
File
modules/social_features/social_follow_taxonomy/modules/social_follow_tag/src/Plugin/ActivityContext/FollowTagActivityContext.php
View source
<?php
namespace Drupal\social_follow_tag\Plugin\ActivityContext;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\social_follow_taxonomy\Plugin\ActivityContext\FollowTaxonomyActivityContext;
use Drupal\Core\Entity\EntityInterface;
use Drupal\group\Entity\GroupInterface;
use Drupal\user\UserInterface;
class FollowTagActivityContext extends FollowTaxonomyActivityContext {
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 [];
}
$group = _social_group_get_current_group($entity);
$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();
$users = $this->entityTypeManager
->getStorage('user')
->loadMultiple($uids);
foreach ($users as $recipient) {
if (!$recipient instanceof UserInterface) {
continue;
}
if ($recipient
->id() === $entity
->getOwnerId()) {
continue;
}
if ($recipient
->isBlocked() || !$recipient
->getLastLoginTime()) {
continue;
}
if (!$this
->haveAccessToNode($recipient, $entity
->id())) {
continue;
}
if (is_null($group) || !$group
->getMember($recipient)) {
$recipients[] = [
'target_type' => 'user',
'target_id' => $recipient
->id(),
];
}
}
return $recipients;
}
}