diff --git a/config/schema/content_moderation_notifications.schema.yml b/config/schema/content_moderation_notifications.schema.yml index 0a55a22..d12e362 100644 --- a/config/schema/content_moderation_notifications.schema.yml +++ b/config/schema/content_moderation_notifications.schema.yml @@ -25,6 +25,9 @@ content_moderation_notifications.content_moderation_notification.*: author: type: boolean label: 'Author' + site_mail: + type: boolean + label: Disable site mail emails: type: string label: 'Emails' diff --git a/src/ContentModerationNotificationInterface.php b/src/ContentModerationNotificationInterface.php index d6c03e9..6c2cf6e 100644 --- a/src/ContentModerationNotificationInterface.php +++ b/src/ContentModerationNotificationInterface.php @@ -25,6 +25,14 @@ interface ContentModerationNotificationInterface extends ConfigEntityInterface { */ public function sendToAuthor(); + /** + * Send the notification to the site mail address. + * + * @return bool + * Returns FALSE if the notification should be sent to site mail address. + */ + public function disableSiteMail(); + /** * Gets the workflow ID. * diff --git a/src/Entity/ContentModerationNotification.php b/src/Entity/ContentModerationNotification.php index a23ccde..d25d729 100644 --- a/src/Entity/ContentModerationNotification.php +++ b/src/Entity/ContentModerationNotification.php @@ -51,6 +51,7 @@ use Drupal\Core\Entity\EntityStorageInterface; * "transitions", * "roles", * "author", + * "site_mail", * "emails", * "subject", * "body", @@ -67,6 +68,13 @@ class ContentModerationNotification extends ConfigEntityBase implements ContentM */ public $author = FALSE; + /** + * Disable notification to the site mail address. + * + * @var bool + */ + public $site_mail = FALSE; + /** * The notification body value and format. * @@ -177,4 +185,11 @@ class ContentModerationNotification extends ConfigEntityBase implements ContentM return $this->get('author'); } + /** + * {@inheritdoc} + */ + public function disableSiteMail() { + return (bool) $this->get('site_mail'); + } + } diff --git a/src/Form/ContentModerationNotificationsFormBase.php b/src/Form/ContentModerationNotificationsFormBase.php index a6bfeeb..8cbaef8 100644 --- a/src/Form/ContentModerationNotificationsFormBase.php +++ b/src/Form/ContentModerationNotificationsFormBase.php @@ -173,6 +173,12 @@ class ContentModerationNotificationsFormBase extends EntityForm { '#default_value' => $content_moderation_notification->sendToAuthor(), '#description' => $this->t('Send notifications to the current author of the content.'), ]; + $form['site_mail'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Disable the site email address'), + '#default_value' => $content_moderation_notification->disableSiteMail(), + '#description' => $this->t('Do not send notifications to the site email address.'), + ]; $form['emails'] = [ '#type' => 'textfield', diff --git a/src/Notification.php b/src/Notification.php index 867cf4d..2a86095 100644 --- a/src/Notification.php +++ b/src/Notification.php @@ -169,11 +169,13 @@ class Notification implements NotificationInterface { // Force to BCC. $data['params']['headers']['Bcc'] = implode(',', $data['to']); - // Displayed 'to' address. - // @todo Make this configurable. - $recipient = \Drupal::config('system.site')->get('mail'); - - $this->mailManager->mail('content_moderation_notifications', 'content_moderation_notification', $recipient, $data['langcode'], $data['params'], NULL, TRUE); + $recipient = ''; + if (!$notification->disableSiteMail()) { + $recipient = \Drupal::config('system.site')->get('mail'); + } + if (!empty($data['params']['headers']['Bcc']) || !empty($recipient)) { + $this->mailManager->mail('content_moderation_notifications', 'content_moderation_notification', $recipient, $data['langcode'], $data['params'], NULL, TRUE); + } } }