Skip to content
Snippets Groups Projects

Issue #3489931: Allow multiple email recipients.

Closes #3489931

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
139 $to = $this->configFactory->get('system.site')->get('mail');
140 $params['message'] = $message;
141 $langcode = $this->languageManager->getCurrentLanguage()->getId();
142 $send = TRUE;
143
144 $result = $this->pluginManagerMail->mail($module, $key, $to, $langcode, $params, NULL, $send);
145 return (bool) $result['result'];
146 }
147
148 // Split emails by newline and remove empty lines
149 $email_list = array_filter(explode("\n", $emails));
150 foreach ($email_list as $to) {
151 $to = trim($to);
152 if (!empty($to)) {
153 $params['message'] = $message;
154 $langcode = $this->languageManager->getCurrentLanguage()->getId();
  • 130 * Whether the message was sent or not.
    131 * Whether all messages were sent successfully.
    131 132 */
    132 public function notifyEmail($message, $email = NULL) {
    133 public function notifyEmail($message, $emails = NULL) {
    133 134 $module = 'migration_notify';
    134 135 $key = 'migration_notify';
    135 $to = empty($email) ? $this->configFactory->get('system.site')->get('mail') : $email;
    136 $params['message'] = $message;
    137 $langcode = $this->languageManager->getCurrentLanguage()->getId();
    138 $send = TRUE;
    136 $success = TRUE;
    137
    138 if (empty($emails)) {
    139 $to = $this->configFactory->get('system.site')->get('mail');
    140 $params['message'] = $message;
  • 131 132 */
    132 public function notifyEmail($message, $email = NULL) {
    133 public function notifyEmail($message, $emails = NULL) {
    133 134 $module = 'migration_notify';
    134 135 $key = 'migration_notify';
    135 $to = empty($email) ? $this->configFactory->get('system.site')->get('mail') : $email;
    136 $params['message'] = $message;
    137 $langcode = $this->languageManager->getCurrentLanguage()->getId();
    138 $send = TRUE;
    136 $success = TRUE;
    137
    138 if (empty($emails)) {
    139 $to = $this->configFactory->get('system.site')->get('mail');
    140 $params['message'] = $message;
    141 $langcode = $this->languageManager->getCurrentLanguage()->getId();
    142 $send = TRUE;
  • 136 $success = TRUE;
    137
    138 if (empty($emails)) {
    139 $to = $this->configFactory->get('system.site')->get('mail');
    140 $params['message'] = $message;
    141 $langcode = $this->languageManager->getCurrentLanguage()->getId();
    142 $send = TRUE;
    143
    144 $result = $this->pluginManagerMail->mail($module, $key, $to, $langcode, $params, NULL, $send);
    145 return (bool) $result['result'];
    146 }
    147
    148 // Split emails by newline and remove empty lines
    149 $email_list = array_filter(explode("\n", $emails));
    150 foreach ($email_list as $to) {
    151 $to = trim($to);
  • 144 $result = $this->pluginManagerMail->mail($module, $key, $to, $langcode, $params, NULL, $send);
    145 return (bool) $result['result'];
    146 }
    147
    148 // Split emails by newline and remove empty lines
    149 $email_list = array_filter(explode("\n", $emails));
    150 foreach ($email_list as $to) {
    151 $to = trim($to);
    152 if (!empty($to)) {
    153 $params['message'] = $message;
    154 $langcode = $this->languageManager->getCurrentLanguage()->getId();
    155 $send = TRUE;
    156
    157 $result = $this->pluginManagerMail->mail($module, $key, $to, $langcode, $params, NULL, $send);
    158 if (!$result['result']) {
    159 $success = FALSE;
  • 341 353 ->save();
    342 354 }
    343 355
    356 /**
    357 * {@inheritdoc}
    358 */
    359 public function validateForm(array &$form, FormStateInterface $form_state) {
    360 parent::validateForm($form, $form_state);
    361
    362 // Only validate if email notifications are enabled
  • Gaurav Gupta added 1 commit

    added 1 commit

    Compare with previous version

  • 160 172 '#default_value' => $config->get('email'),
    161 173 ];
    162 174 $form['email_to'] = [
    163 '#type' => 'email',
    164 '#title' => $this->t('Send email to this address'),
    165 '#description' => $this->t('Send the email to the specified address. Leave empty for %email (site administrator)', ['%email' => $email]),
    166 '#default_value' => $config->get('email_to'),
    175 '#type' => 'textarea',
    176 '#title' => $this->t('Send email to these addresses'),
    177 '#description' => $this->t('Send the email to the specified addresses. One email per line. Leave empty for %email (site administrator)', ['%email' => $email]),
    178 '#default_value' => is_array($config->get('email_to')) ? implode("\n", $config->get('email_to')) : '',
  • 327 339 $cron = $form_state->getValue('cron');
    328 340 $daily = $form_state->getValue('daily');
    329 341 $email = $form_state->getValue('email');
    330 $email_to = $form_state->getValue('email_to');
    331 342 $slack = $form_state->getValue('slack');
    332 343 $message = $form_state->getValue('stuck_message');
    333 344
    345 $valid_emails = $form_state->get('valid_emails') ?: [];
  • 363 $valid_emails = [];
    364 $emails = $form_state->getValue('email_to');
    365 if (!empty($emails)) {
    366 foreach (array_filter(explode("\n", $emails)) as $email) {
    367 if ($trimmed = trim($email)) {
    368 if (!$this->emailValidator->isValid($trimmed)) {
    369 $form_state->setErrorByName('email_to', $this->t('The email address %email is not valid.', [
    370 '%email' => $trimmed,
    371 ]));
    372 }
    373 else {
    374 $valid_emails[] = $trimmed;
    375 }
    376 }
    377 }
    378 $form_state->set('valid_emails', $valid_emails);
  • Gaurav Gupta added 1 commit

    added 1 commit

    Compare with previous version

  • 331 343 $slack = $form_state->getValue('slack');
    332 344 $message = $form_state->getValue('stuck_message');
    333 345
    346 $cleaned_emails = '';
    347 if (!empty($email_to)) {
    348 $email_list = array_filter(array_map('trim', explode("\n", $email_to)));
  • 338 358 ->set('email', $email)
    339 ->set('email_to', $email_to)
    359 ->set('email_to', $cleaned_emails)
    340 360 ->set('stuck_message', $message)
    341 361 ->save();
    342 362 }
    343 363
    364 /**
    365 * {@inheritdoc}
    366 */
    367 public function validateForm(array &$form, FormStateInterface $form_state) {
    368 parent::validateForm($form, $form_state);
    369
    370 $emails = $form_state->getValue('email_to');
    371 if (!empty($emails)) {
    372 $email_list = array_filter(array_map('trim', explode("\n", $emails)));
  • 160 172 '#default_value' => $config->get('email'),
    161 173 ];
    162 174 $form['email_to'] = [
    163 '#type' => 'email',
    164 '#title' => $this->t('Send email to this address'),
    165 '#description' => $this->t('Send the email to the specified address. Leave empty for %email (site administrator)', ['%email' => $email]),
    175 '#type' => 'textarea',
    176 '#title' => $this->t('Send email to these addresses'),
    177 '#description' => $this->t('Send the email to the specified addresses. One email per line. Leave empty for %email (site administrator)', ['%email' => $email]),
  • 128 129 *
    129 130 * @return bool
    130 * Whether the message was sent or not.
    131 * Whether all messages were sent successfully.
    131 132 */
    132 public function notifyEmail($message, $email = NULL) {
    133 public function notifyEmail($message, $emails = NULL) {
    133 134 $module = 'migration_notify';
    134 135 $key = 'migration_notify';
    135 $to = empty($email) ? $this->configFactory->get('system.site')->get('mail') : $email;
    136 $emails = empty($emails) ? $this->configFactory->get('system.site')->get('mail') : $emails;
    136 137 $params['message'] = $message;
    137 138 $langcode = $this->languageManager->getCurrentLanguage()->getId();
    138 139 $send = TRUE;
    140 $success = TRUE;
    141 foreach (explode("\n", $emails) as $to) {
  • Gaurav Gupta added 1 commit

    added 1 commit

    Compare with previous version

  • Please register or sign in to reply
    Loading