You are here

class FollowTagActivityContext in Open Social 10.2.x

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_follow_taxonomy/modules/social_follow_tag/src/Plugin/ActivityContext/FollowTagActivityContext.php \Drupal\social_follow_tag\Plugin\ActivityContext\FollowTagActivityContext
  2. 10.0.x modules/social_features/social_follow_taxonomy/modules/social_follow_tag/src/Plugin/ActivityContext/FollowTagActivityContext.php \Drupal\social_follow_tag\Plugin\ActivityContext\FollowTagActivityContext
  3. 10.1.x modules/social_features/social_follow_taxonomy/modules/social_follow_tag/src/Plugin/ActivityContext/FollowTagActivityContext.php \Drupal\social_follow_tag\Plugin\ActivityContext\FollowTagActivityContext

Provides a 'FollowTagActivityContext' activity context plugin.

Plugin annotation


@ActivityContext(
 id = "follow_tag_activity_context",
 label = @Translation("Following tag activity context"),
)

Hierarchy

Expanded class hierarchy of FollowTagActivityContext

File

modules/social_features/social_follow_taxonomy/modules/social_follow_tag/src/Plugin/ActivityContext/FollowTagActivityContext.php, line 19

Namespace

Drupal\social_follow_tag\Plugin\ActivityContext
View source
class FollowTagActivityContext extends FollowTaxonomyActivityContext {

  /**
   * Returns recipients from followed taxonomies.
   */
  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 entity group if exists.
    $group = _social_group_get_current_group($entity);

    // 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;
      }

      // We don't send notifications to content creator.
      if ($recipient
        ->id() === $entity
        ->getOwnerId()) {
        continue;
      }

      // Do not send notification for inactive user.
      if ($recipient
        ->isBlocked() || !$recipient
        ->getLastLoginTime()) {
        continue;
      }

      // Check if user have access to view node.
      if (!$this
        ->haveAccessToNode($recipient, $entity
        ->id())) {
        continue;
      }
      if (is_null($group) || !$group
        ->getMember($recipient)) {
        $recipients[] = [
          'target_type' => 'user',
          'target_id' => $recipient
            ->id(),
        ];
      }
    }
    return $recipients;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ActivityContextBase::$activityFactory protected property The activity factory service.
ActivityContextBase::$entityQuery private property The entity query.
ActivityContextBase::$entityTypeManager protected property The entity type manager.
ActivityContextBase::getRecipientsFromPost public function Returns recipients from post.
FollowTagActivityContext::getRecipientsWhoFollowTaxonomy public function Returns recipients from followed taxonomies. Overrides FollowTaxonomyActivityContext::getRecipientsWhoFollowTaxonomy
FollowTaxonomyActivityContext::$connection protected property The database connection.
FollowTaxonomyActivityContext::$groupHelperService protected property The group helper service.
FollowTaxonomyActivityContext::$moduleHandler protected property The module handler.
FollowTaxonomyActivityContext::create public static function Creates an instance of the plugin. Overrides ActivityContextBase::create
FollowTaxonomyActivityContext::getListOfTagsFields public function Returns list of field names that needs to check for entity validation.
FollowTaxonomyActivityContext::getRecipients public function Returns a batched list of recipients for this context. Overrides ActivityContextBase::getRecipients
FollowTaxonomyActivityContext::haveAccessToNode protected function Checks if recipient have access to view related node.
FollowTaxonomyActivityContext::isValidEntity public function Determines if the entity is valid for this context. Overrides ActivityContextBase::isValidEntity
FollowTaxonomyActivityContext::taxonomyTermsList public function List of taxonomy terms.
FollowTaxonomyActivityContext::__construct public function ActivityContextBase constructor. Overrides ActivityContextBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.