PrivateMessageActivityContext.php in Open Social 8
Same filename and directory in other branches
- 8.9 modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php
- 8.2 modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php
- 8.3 modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php
- 8.4 modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php
- 8.5 modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php
- 8.6 modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php
- 8.7 modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php
- 8.8 modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php
- 10.3.x modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php
- 10.0.x modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php
- 10.1.x modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php
- 10.2.x modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php
File
modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.phpView source
<?php
namespace Drupal\social_private_message\Plugin\ActivityContext;
use Drupal\activity_creator\Plugin\ActivityContextBase;
use Drupal\private_message\Entity\PrivateMessage;
use Drupal\user\Entity\User;
/**
* Provides a 'PrivateMessageActivityContext' activity context.
*
* @ActivityContext(
* id = "private_message_activity_context",
* label = @Translation("Private message activity context"),
* )
*/
class PrivateMessageActivityContext extends ActivityContextBase {
/**
* {@inheritdoc}
*/
public function getRecipients(array $data, $last_uid, $limit) {
$recipients = [];
// 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];
if ($related_object['target_type'] == 'private_message') {
$related_object = $data['related_object'][0];
if ($related_object['target_type'] === 'private_message') {
$private_message = PrivateMessage::load($related_object['target_id']);
// Must be a Private Message.
if ($private_message instanceof PrivateMessage) {
$pmService = \Drupal::service('private_message.service');
// Get the thread of this message.
$thread = $pmService
->getThreadFromMessage($private_message);
// Get all members of this thread.
/** @var \Drupal\private_message\Entity\PrivateMessageThreadInterface $members */
$members = $thread
->getMembers();
// Loop over all PMT participants.
foreach ($members as $member) {
if ($member instanceof User) {
// Filter out the author of this message.
if ($member
->id() == $data['actor']) {
continue;
}
// Create the recipients array.
$recipients[] = [
'target_type' => 'user',
'target_id' => $member
->id(),
];
}
}
}
}
}
}
return $recipients;
}
/**
* Check if it's valid.
*/
public function isValidEntity($entity) {
if ($entity
->getEntityTypeId() === 'private_message') {
return TRUE;
}
return FALSE;
}
}
Classes
Name | Description |
---|---|
PrivateMessageActivityContext | Provides a 'PrivateMessageActivityContext' activity context. |