class FollowTaxonomyActivityContext in Open Social 10.1.x
Same name and namespace in other branches
- 10.3.x modules/social_features/social_follow_taxonomy/src/Plugin/ActivityContext/FollowTaxonomyActivityContext.php \Drupal\social_follow_taxonomy\Plugin\ActivityContext\FollowTaxonomyActivityContext
- 10.0.x modules/social_features/social_follow_taxonomy/src/Plugin/ActivityContext/FollowTaxonomyActivityContext.php \Drupal\social_follow_taxonomy\Plugin\ActivityContext\FollowTaxonomyActivityContext
- 10.2.x modules/social_features/social_follow_taxonomy/src/Plugin/ActivityContext/FollowTaxonomyActivityContext.php \Drupal\social_follow_taxonomy\Plugin\ActivityContext\FollowTaxonomyActivityContext
Provides a 'FollowTaxonomyActivityContext' activity context plugin.
Plugin annotation
@ActivityContext(
id = "follow_taxonomy_activity_context",
label = @Translation("Following taxonomy activity context"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\activity_creator\Plugin\ActivityContextBase implements ActivityContextInterface, ContainerFactoryPluginInterface
- class \Drupal\social_follow_taxonomy\Plugin\ActivityContext\FollowTaxonomyActivityContext
- class \Drupal\activity_creator\Plugin\ActivityContextBase implements ActivityContextInterface, ContainerFactoryPluginInterface
Expanded class hierarchy of FollowTaxonomyActivityContext
1 file declares its use of FollowTaxonomyActivityContext
- FollowTagActivityContext.php in modules/
social_features/ social_follow_taxonomy/ modules/ social_follow_tag/ src/ Plugin/ ActivityContext/ FollowTagActivityContext.php
File
- modules/
social_features/ social_follow_taxonomy/ src/ Plugin/ ActivityContext/ FollowTaxonomyActivityContext.php, line 23
Namespace
Drupal\social_follow_taxonomy\Plugin\ActivityContextView source
class FollowTaxonomyActivityContext extends ActivityContextBase {
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* ActivityContextBase constructor.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\Query\Sql\QueryFactory $entity_query
* The entity query.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\activity_creator\ActivityFactory $activity_factory
* The activity factory service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, QueryFactory $entity_query, EntityTypeManagerInterface $entity_type_manager, ActivityFactory $activity_factory, ModuleHandlerInterface $module_handler) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_query, $entity_type_manager, $activity_factory);
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity.query.sql'), $container
->get('entity_type.manager'), $container
->get('activity_creator.activity_factory'), $container
->get('module_handler'));
}
/**
* {@inheritdoc}
*/
public function getRecipients(array $data, $last_uid, $limit) {
// It could happen that a notification has been queued but the account has
// since been deleted and message author is anonymous.
if (!empty($data['actor']) && $data['actor'] === 0) {
return [];
}
$recipients = [];
// We only know the context if there is a related object.
if (isset($data['related_object']) && !empty($data['related_object'])) {
$related_entity = $this->activityFactory
->getActivityRelatedEntity($data);
if ($related_entity['target_type'] == 'node' || $related_entity['target_type'] == 'post') {
$recipients += $this
->getRecipientsWhoFollowTaxonomy($related_entity, $data);
}
}
return $recipients;
}
/**
* List of taxonomy terms.
*/
public function taxonomyTermsList($entity) {
$term_ids = social_follow_taxonomy_terms_list($entity);
return $term_ids;
}
/**
* 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;
}
// 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;
}
/**
* {@inheritdoc}
*/
public function isValidEntity(EntityInterface $entity) {
if (!$entity instanceof ContentEntityInterface) {
return FALSE;
}
// Check entity type.
switch ($entity
->getEntityTypeId()) {
case 'node':
foreach ($this
->getListOfTagsFields() as $field_name) {
if ($entity
->hasField($field_name)) {
return TRUE;
}
}
return FALSE;
}
return FALSE;
}
/**
* Returns list of field names that needs to check for entity validation.
*
* @return string[]
* List of filed names.
*/
public function getListOfTagsFields() {
$fields_to_check = [
'social_tagging',
];
$this->moduleHandler
->alter('social_follow_taxonomy_fields', $fields_to_check);
return $fields_to_check;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ActivityContextBase:: |
protected | property | The activity factory service. | |
ActivityContextBase:: |
private | property | The entity query. | |
ActivityContextBase:: |
protected | property | The entity type manager. | |
ActivityContextBase:: |
public | function | Returns recipients from post. | |
FollowTaxonomyActivityContext:: |
protected | property | The module handler. | |
FollowTaxonomyActivityContext:: |
public static | function |
Creates an instance of the plugin. Overrides ActivityContextBase:: |
|
FollowTaxonomyActivityContext:: |
public | function | Returns list of field names that needs to check for entity validation. | |
FollowTaxonomyActivityContext:: |
public | function |
Returns a batched list of recipients for this context. Overrides ActivityContextBase:: |
|
FollowTaxonomyActivityContext:: |
public | function | Returns recipients from followed taxonomies. | 1 |
FollowTaxonomyActivityContext:: |
public | function |
Determines if the entity is valid for this context. Overrides ActivityContextBase:: |
|
FollowTaxonomyActivityContext:: |
public | function | List of taxonomy terms. | |
FollowTaxonomyActivityContext:: |
public | function |
ActivityContextBase constructor. Overrides ActivityContextBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. |