Notification.php in Content Moderation Notifications 8.2
File
src/Notification.php
View source
<?php
namespace Drupal\content_moderation_notifications;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Mail\MailManager;
class Notification implements NotificationInterface {
protected $mailManager;
public function __construct(MailManager $mail_manager) {
$this->mailManager = $mail_manager;
}
public function sendNotification(EntityInterface $entity, array $notifications) {
foreach ($notifications as $notification) {
$data['langcode'] = \Drupal::currentUser()
->getPreferredLangcode();
$data['notification'] = $notification;
$data['params']['subject'] = $notification->subject;
$data['params']['message'] = check_markup($notification->body['value'], $notification->body['format']);
$data['params']['context'] = [
'entity' => $entity,
'user' => \Drupal::currentUser(),
];
$data['to'] = [];
if ($notification->author) {
$data['to'][] = $entity
->getOwner()->mail->value;
}
$roles = array_keys(array_filter($notification->roles));
foreach ($roles as $role) {
$role_users = \Drupal::service('entity_type.manager')
->getStorage('user')
->loadByProperties([
'roles' => $role,
]);
foreach ($role_users as $role_user) {
$data['to'][] = $role_user->mail->value;
}
}
$adhoc_emails = array_map('trim', explode(',', $notification->emails));
foreach ($adhoc_emails as $email) {
$data['to'][] = $email;
}
\Drupal::moduleHandler()
->alter('content_moderation_notification_mail_data', $entity, $data);
$data['to'] = array_filter($data['to']);
$data['to'] = array_unique($data['to']);
$this->mailManager
->mail('content_moderation_notifications', 'content_moderation_notification', implode(',', $data['to']), $data['langcode'], $data['params'], NULL, TRUE);
}
}
}
Classes
Name |
Description |
Notification |
General service for moderation-related questions about Entity API. |