You are here

class FollowTagActivityContext in Open Social 10.0.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.1.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.2.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 [];
    }
    $storage = $this->entityTypeManager
      ->getStorage('flagging');
    $flaggings = $storage
      ->loadByProperties([
      'flag_id' => 'follow_term',
      'entity_type' => 'taxonomy_term',
      'entity_id' => $tids,
    ]);
    foreach ($flaggings as $flagging) {

      /** @var \Drupal\flag\FlaggingInterface $flagging */
      $recipient = $flagging
        ->getOwner();

      // 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;
      }
      $group = _social_group_get_current_group($entity);
      if ($group instanceof GroupInterface) {
        if (!$group
          ->getMember($recipient)) {

          // We don't send notifications to content creator.
          if ($recipient
            ->id() !== $entity
            ->getOwnerId()) {
            if (!in_array($recipient
              ->id(), array_column($recipients, 'target_id'))) {
              $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::$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::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.