class MentionActivityContext in Open Social 8.5
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.6 modules/social_features/social_mentions/src/Plugin/ActivityContext/MentionActivityContext.php \Drupal\social_mentions\Plugin\ActivityContext\MentionActivityContext
- 8.7 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 = \Drupal::entityTypeManager()
->getStorage('mentions');
if ($related_object['target_type'] == 'mentions') {
$mentions[] = $mentions_storage
->load($related_object['target_id']);
}
else {
$entity_storage = \Drupal::entityTypeManager()
->getStorage($related_object['target_type']);
$entity = $entity_storage
->load($related_object['target_id']);
$mentions = $this
->getMentionsFromRelatedEntity($entity);
}
if (!empty($mentions)) {
foreach ($mentions as $mention) {
if (isset($mention->uid)) {
$uid = $mention
->getMentionedUserId();
// Don't send notifications to myself.
if ($uid === $data['actor']) {
continue;
}
$entity_storage = \Drupal::entityTypeManager()
->getStorage($mention
->getMentionedEntityTypeId());
$mentioned_entity = $entity_storage
->load($mention
->getMentionedEntityId());
$account = User::load($uid);
$access = $mentioned_entity
->access('view', $account);
if ($access) {
$recipients[] = [
'target_type' => 'user',
'target_id' => $mention
->getMentionedUserId(),
];
}
}
}
}
}
return $recipients;
}
/**
* Check for valid entity.
*/
public function isValidEntity($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.
*/
public function getMentionsFromRelatedEntity($entity) {
if ($entity
->getEntityTypeId() === 'comment') {
if ($entity
->getParentComment()) {
$entity = $entity
->getParentComment();
}
}
// Mention entity can't be loaded at time of new post or comment creation.
$mentions = \Drupal::entityTypeManager()
->getStorage('mentions')
->loadByProperties([
'entity_type' => $entity
->getEntityTypeId(),
'entity_id' => $entity
->id(),
]);
return $mentions;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ActivityContextBase:: |
private | property | Entity query. | |
ActivityContextBase:: |
protected | property | Entity type manager. | |
ActivityContextBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
1 |
ActivityContextBase:: |
public | function | Returns recipients from post. | |
ActivityContextBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
1 |
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. |