class MentionActivityContext in Open Social 8.7
Same name and namespace in other branches
- 8.9 modules/social_features/social_mentions/src/Plugin/ActivityContext/MentionActivityContext.php \Drupal\social_mentions\Plugin\ActivityContext\MentionActivityContext
- 8 modules/social_features/social_mentions/src/Plugin/ActivityContext/MentionActivityContext.php \Drupal\social_mentions\Plugin\ActivityContext\MentionActivityContext
- 8.2 modules/social_features/social_mentions/src/Plugin/ActivityContext/MentionActivityContext.php \Drupal\social_mentions\Plugin\ActivityContext\MentionActivityContext
- 8.3 modules/social_features/social_mentions/src/Plugin/ActivityContext/MentionActivityContext.php \Drupal\social_mentions\Plugin\ActivityContext\MentionActivityContext
- 8.4 modules/social_features/social_mentions/src/Plugin/ActivityContext/MentionActivityContext.php \Drupal\social_mentions\Plugin\ActivityContext\MentionActivityContext
- 8.5 modules/social_features/social_mentions/src/Plugin/ActivityContext/MentionActivityContext.php \Drupal\social_mentions\Plugin\ActivityContext\MentionActivityContext
- 8.6 modules/social_features/social_mentions/src/Plugin/ActivityContext/MentionActivityContext.php \Drupal\social_mentions\Plugin\ActivityContext\MentionActivityContext
- 8.8 modules/social_features/social_mentions/src/Plugin/ActivityContext/MentionActivityContext.php \Drupal\social_mentions\Plugin\ActivityContext\MentionActivityContext
- 10.3.x modules/social_features/social_mentions/src/Plugin/ActivityContext/MentionActivityContext.php \Drupal\social_mentions\Plugin\ActivityContext\MentionActivityContext
- 10.0.x modules/social_features/social_mentions/src/Plugin/ActivityContext/MentionActivityContext.php \Drupal\social_mentions\Plugin\ActivityContext\MentionActivityContext
- 10.1.x modules/social_features/social_mentions/src/Plugin/ActivityContext/MentionActivityContext.php \Drupal\social_mentions\Plugin\ActivityContext\MentionActivityContext
- 10.2.x modules/social_features/social_mentions/src/Plugin/ActivityContext/MentionActivityContext.php \Drupal\social_mentions\Plugin\ActivityContext\MentionActivityContext
Provides a 'MentionActivityContext' activity context.
Plugin annotation
@ActivityContext(
id = "mention_activity_context",
label = @Translation("Mention activity context"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\activity_creator\Plugin\ActivityContextBase implements ActivityContextInterface, ContainerFactoryPluginInterface
- class \Drupal\social_mentions\Plugin\ActivityContext\MentionActivityContext
- class \Drupal\activity_creator\Plugin\ActivityContextBase implements ActivityContextInterface, ContainerFactoryPluginInterface
Expanded class hierarchy of MentionActivityContext
File
- modules/
social_features/ social_mentions/ src/ Plugin/ ActivityContext/ MentionActivityContext.php, line 16
Namespace
Drupal\social_mentions\Plugin\ActivityContextView source
class MentionActivityContext extends ActivityContextBase {
/**
* {@inheritdoc}
*/
public function getRecipients(array $data, $last_uid, $limit) {
$recipients = [];
$mentions = [];
// We only know the context if there is a related object.
if (isset($data['related_object']) && !empty($data['related_object'])) {
$related_object = $data['related_object'][0];
$mentions_storage = $this->entityTypeManager
->getStorage('mentions');
if ($related_object['target_type'] === 'mentions') {
$mentions[] = $mentions_storage
->load($related_object['target_id']);
}
else {
$entity_storage = $this->entityTypeManager
->getStorage($related_object['target_type']);
$entity = $entity_storage
->load($related_object['target_id']);
$mentions = $this
->getMentionsFromRelatedEntity($entity);
}
if (!empty($mentions)) {
/** @var \Drupal\mentions\MentionsInterface $mention */
foreach ($mentions as $mention) {
if (isset($mention->uid)) {
$uid = $mention
->getMentionedUserId();
// Don't send notifications to myself.
if ($uid === $data['actor']) {
continue;
}
$entity_storage = $this->entityTypeManager
->getStorage($mention
->getMentionedEntityTypeId());
$mentioned_entity = $entity_storage
->load($mention
->getMentionedEntityId());
/** @var \Drupal\user\UserInterface $account */
$account = $mention->uid->entity;
if ($mentioned_entity
->access('view', $account)) {
$recipients[] = [
'target_type' => 'user',
'target_id' => $uid,
];
}
}
}
}
}
return $recipients;
}
/**
* Check for valid entity.
*/
public function isValidEntity(EntityInterface $entity) {
if ($entity
->getEntityTypeId() === 'mentions') {
return TRUE;
}
// Special cases for comments and posts.
$allowed_content_types = [
'comment',
];
if (in_array($entity
->getEntityTypeId(), $allowed_content_types)) {
$mentions = $this
->getMentionsFromRelatedEntity($entity);
if (!empty($mentions)) {
return TRUE;
}
}
return FALSE;
}
/**
* Get the mentions from the related entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity object.
*
* @return \Drupal\Core\Entity\EntityInterface[]
* The mentions.
*/
public function getMentionsFromRelatedEntity(EntityInterface $entity) {
if ($entity
->getEntityTypeId() === 'comment') {
if ($entity
->hasParentComment()) {
$entity = $entity
->getParentComment();
}
}
// Mention entity can't be loaded at time of new post or comment creation.
return $this->entityTypeManager
->getStorage('mentions')
->loadByProperties([
'entity_type' => $entity
->getEntityTypeId(),
'entity_id' => $entity
->id(),
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ActivityContextBase:: |
private | property | The entity query. | |
ActivityContextBase:: |
protected | property | The entity type manager. | |
ActivityContextBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
3 |
ActivityContextBase:: |
public | function | Returns recipients from post. | |
ActivityContextBase:: |
public | function |
ActivityContextBase constructor. Overrides PluginBase:: |
3 |
MentionActivityContext:: |
public | function | Get the mentions from the related entity. | |
MentionActivityContext:: |
public | function |
Returns a batched list of recipients for this context. Overrides ActivityContextBase:: |
|
MentionActivityContext:: |
public | function |
Check for valid entity. 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:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. |