Skip to content
Snippets Groups Projects

Issue #3267556: MailManagerReplacement::mail() differences from MailManager::mail() return arguments

Closed Issue #3267556: MailManagerReplacement::mail() differences from MailManager::mail() return arguments
2 unresolved threads
Closed ekes requested to merge issue/symfony_mailer-3267556:3267556-mailmanagerreplacement into 1.x
2 unresolved threads
1 file
+ 32
2
Compare changes
  • Side-by-side
  • Inline
@@ -10,6 +10,7 @@ use Drupal\Core\Mail\MailManager;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\symfony_mailer\EmailFactory;
use Drupal\symfony_mailer\EmailInterface;
/**
* Provides a Symfony Mailer replacement for MailManager.
@@ -74,8 +75,37 @@ class MailManagerReplacement extends MailManager {
if ($send) {
$result = $email->send();
}
// Set the 'send' element for Webform module.
return ['result' => $result, 'send' => $send];
return $this->emailToArray($email) + ['result' => $result];
}
/**
* Gets a message array for an Email.
*
* @param \Drupal\symfony_mailer\EmailInterface $email
* The email to convert.
*
* @return array
* Message array as \Drupal\Core\Mail\MailManager::doMail().
*/
public function emailToArray(EmailInterface $email) {
$headers = $email->getHeaders();
$module = $email->getType();
$key = $email->getSubType();
    • Let's create a function like this:

        /**
         * Gets a message array for an Email.
         *
         * @param \Drupal\symfony_mailer\EmailInterface $email
         *   The email to convert.
         *
         * @return array
         *   Message array.
         */
        public function emailToArray(EmailInterface $email) {

      Then we can also call the function in LegacyEmailBuilder::preRender(). Then let's remove LegacyEmailBuilder::getMessage() which is now trivial and put all the code in preRender().

Please register or sign in to reply
return [
'id' => $module . '_' . $key,
'module' => $module,
'key' => $key,
'to' => $headers->has('to') ? $headers->get('to')->getBodyAsString() : '',
'from' => $headers->has('from') ? $headers->get('from')->getBodyAsString() : '',
'reply-to' => $headers->has('reply-to') ? $headers->get('reply-to')->getBodyAsString() : '',
'langcode' => $email->getLangcode(),
'params' => $email->getParams(),
'send' => TRUE,
'subject' => $email->getSubject(),
'body' => (string) $email->getTextBody(),
];
}
}
Loading