class PrivateMessageThreadManager in Private Message 8
Same name and namespace in other branches
- 8.2 src/Service/PrivateMessageThreadManager.php \Drupal\private_message\Service\PrivateMessageThreadManager
The Private Message generator class.
@package Drupal\private_message\Service
Hierarchy
- class \Drupal\private_message\Service\PrivateMessageThreadManager implements PrivateMessageThreadManagerInterface
Expanded class hierarchy of PrivateMessageThreadManager
1 string reference to 'PrivateMessageThreadManager'
File
- src/
Service/ PrivateMessageThreadManager.php, line 14
Namespace
Drupal\private_message\ServiceView source
class PrivateMessageThreadManager implements PrivateMessageThreadManagerInterface {
/**
* The private message service.
*
* @var \Drupal\private_message\Service\PrivateMessageServiceInterface
*/
private $privateMessageService;
/**
* The private message mailer service.
*
* @var \Drupal\private_message\Service\PrivateMessageMailerInterface
*/
private $privateMessageMailer;
/**
* The private message.
*
* @var \Drupal\private_message\Entity\PrivateMessageInterface
*/
private $message;
/**
* The message recipients.
*
* @var \Drupal\Core\Session\AccountInterface[]
*/
private $recipients = [];
/**
* An array of members to exclude from notification emails.
*
* @var \Drupal\Core\Session\AccountInterface[]
*/
private $excludeFromMail = [];
/**
* The private message thread.
*
* @var \Drupal\private_message\Entity\PrivateMessageThreadInterface|null
*/
private $thread;
/**
* PrivateMessageThreadManager constructor.
*
* @param \Drupal\private_message\Service\PrivateMessageServiceInterface $private_message_service
* The private message service.
* @param \Drupal\private_message\Service\PrivateMessageMailerInterface $mailer
* The private message mailer service.
*/
public function __construct(PrivateMessageServiceInterface $private_message_service, PrivateMessageMailerInterface $mailer) {
$this->privateMessageService = $private_message_service;
$this->privateMessageMailer = $mailer;
}
/**
* {@inheritdoc}
*/
public function saveThread(PrivateMessageInterface $message, array $recipients = [], array $excludeFromMail = [], PrivateMessageThreadInterface $thread = NULL) {
$this->message = $message;
$this->thread = $thread;
$this->recipients = $recipients;
$this->excludeFromMail = $excludeFromMail;
$this
->getThread()
->addMessage()
->sendMail();
}
/**
* If no thread is defined, load one from the thread members.
*
* @return $this
*/
private function getThread() {
if (is_null($this->thread)) {
$this->thread = $this->privateMessageService
->getThreadForMembers($this->recipients);
}
return $this;
}
/**
* Add the new message to the thread.
*
* @return $this
*/
private function addMessage() {
$this->thread
->addMessage($this->message);
$this->thread
->save();
return $this;
}
/**
* Send the notification email.
*
* @return $this
*/
private function sendMail() {
$this->privateMessageMailer
->send($this->message, $this->thread, $this
->getMailRecipients());
return $this;
}
/**
* The users to receive email notifications.
*
* @return \Drupal\Core\Session\AccountInterface[]
* An array of Account objects of the thread memebers who are to receive
* the email notification.
*/
private function getMailRecipients() {
if (empty($this->excludeFromMail)) {
return $this->recipients;
}
return array_filter($this->recipients, function (AccountInterface $account) {
// If this user is in the excluded list, filter them from the recipients
// list so they do not receive the email.
return !in_array($account, $this->excludeFromMail);
});
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PrivateMessageThreadManager:: |
private | property | An array of members to exclude from notification emails. | |
PrivateMessageThreadManager:: |
private | property | The private message. | |
PrivateMessageThreadManager:: |
private | property | The private message mailer service. | |
PrivateMessageThreadManager:: |
private | property | The private message service. | |
PrivateMessageThreadManager:: |
private | property | The message recipients. | |
PrivateMessageThreadManager:: |
private | property | The private message thread. | |
PrivateMessageThreadManager:: |
private | function | Add the new message to the thread. | |
PrivateMessageThreadManager:: |
private | function | The users to receive email notifications. | |
PrivateMessageThreadManager:: |
private | function | If no thread is defined, load one from the thread members. | |
PrivateMessageThreadManager:: |
public | function |
Saves a private message thread. Overrides PrivateMessageThreadManagerInterface:: |
|
PrivateMessageThreadManager:: |
private | function | Send the notification email. | |
PrivateMessageThreadManager:: |
public | function | PrivateMessageThreadManager constructor. |