Commit 1df84875 authored by Adam Shepherd's avatar Adam Shepherd
Browse files

Issue #3253847 by AdamPS: Improvements to Email interface

parent d189afe9
Loading
Loading
Loading
Loading
+7 −13
Changes for modules/symfony_mailer_bc/src/Plugin/EmailBuilder/CommerceEmailBuilder.php: 7 added lines, 13 removed lines.
Original line number Diff line number Diff line
@@ -3,8 +3,7 @@
namespace Drupal\symfony_mailer_bc\Plugin\EmailBuilder;

use Drupal\symfony_mailer\Processor\EmailProcessorBase;
use Drupal\symfony_mailer\RenderedEmailInterface;
use Drupal\symfony_mailer\UnrenderedEmailInterface;
use Drupal\symfony_mailer\EmailInterface;

/**
 * Defines the Email Builder plug-in for commerce module.
@@ -16,30 +15,25 @@ use Drupal\symfony_mailer\UnrenderedEmailInterface;
 *
 * @todo Notes for adopting Symfony Mailer into commerce. It should be possible
 * to remove the MailHandler service. Classes such as OrderReceiptMail could
 * call directly to UnrenderedEmailInterface or even be converted to an
 * EmailBuilder. The commerce_order_receipt template could be retired,
 * switching instead to the email__commerce__order_receipt.
 * call directly to EmailInterface or even be converted to an EmailBuilder. The
 * commerce_order_receipt template could be retired, switching instead to use
 * email__commerce__order_receipt.
 */
class CommerceEmailBuilder extends EmailProcessorBase {

  /**
   * {@inheritdoc}
   */
  public function preRender(UnrenderedEmailInterface $email) {
  public function preRender(EmailInterface $email) {
    $email->setSubject($email->getParam('subject'))
      ->setBody($email->getParam('body'));
  }

  /**
   * {@inheritdoc}
   */
  public function postRender(RenderedEmailInterface $email) {
    if ($from = $email->getParam('from')) {
      $email->getInner()->from($from);
      $email->setFrom($from);
    }

    if ($bcc = $email->getParam('bcc')) {
      $email->getInner()->bcc($bcc);
      $email->setBcc($bcc);
    }
  }

+2 −2
Changes for modules/symfony_mailer_bc/src/Plugin/EmailBuilder/ContactEmailBuilder.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@

namespace Drupal\symfony_mailer_bc\Plugin\EmailBuilder;

use Drupal\symfony_mailer\UnrenderedEmailInterface;
use Drupal\symfony_mailer\EmailInterface;

/**
 * Defines the Email Builder plug-in for contact module personal forms.
@@ -23,7 +23,7 @@ class ContactEmailBuilder extends ContactEmailBuilderBase {
  /**
   * {@inheritdoc}
   */
  public function preRender(UnrenderedEmailInterface $email) {
  public function preRender(EmailInterface $email) {
    parent::preRender($email);
    $recipient = $email->getParams()['recipient'];

+2 −2
Changes for modules/symfony_mailer_bc/src/Plugin/EmailBuilder/ContactEmailBuilderBase.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
namespace Drupal\symfony_mailer_bc\Plugin\EmailBuilder;

use Drupal\symfony_mailer\Processor\EmailProcessorBase;
use Drupal\symfony_mailer\UnrenderedEmailInterface;
use Drupal\symfony_mailer\EmailInterface;

/**
 * Defines a base class for contact module email builders.
@@ -14,7 +14,7 @@ class ContactEmailBuilderBase extends EmailProcessorBase {
  /**
   * {@inheritdoc}
   */
  public function preRender(UnrenderedEmailInterface $email) {
  public function preRender(EmailInterface $email) {
    /** @var \Drupal\user\UserInterface $sender */
    $sender = $email->getParam('sender');
    $contact_message = $email->getParam('contact_message');
+2 −2
Changes for modules/symfony_mailer_bc/src/Plugin/EmailBuilder/ContactPageEmailBuilder.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
namespace Drupal\symfony_mailer_bc\Plugin\EmailBuilder;

use Drupal\Core\Url;
use Drupal\symfony_mailer\UnrenderedEmailInterface;
use Drupal\symfony_mailer\EmailInterface;

/**
 * Defines the Email Builder plug-in for contact module page forms.
@@ -26,7 +26,7 @@ class ContactPageEmailBuilder extends ContactEmailBuilderBase {
  /**
   * {@inheritdoc}
   */
  public function preRender(UnrenderedEmailInterface $email) {
  public function preRender(EmailInterface $email) {
    parent::preRender($email);
    $email->setVariable('form', $email->getEntity()->label())
      ->setVariable('form_url', Url::fromRoute('<current>')->toString());
+4 −4
Changes for modules/symfony_mailer_bc/src/Plugin/EmailBuilder/LegacyEmailBuilder.php: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ namespace Drupal\symfony_mailer_bc\Plugin\EmailBuilder;

use Drupal\Component\Render\MarkupInterface;
use Drupal\symfony_mailer\Processor\EmailProcessorBase;
use Drupal\symfony_mailer\UnrenderedEmailInterface;
use Drupal\symfony_mailer\EmailInterface;

/**
 * Defines the Legacy Email Builder plug-in that calls hook_mail().
@@ -14,7 +14,7 @@ class LegacyEmailBuilder extends EmailProcessorBase {
  /**
   * {@inheritdoc}
   */
  public function preRender(UnrenderedEmailInterface $email) {
  public function preRender(EmailInterface $email) {
    $message = $this->getMessage($email);
    $email->setSubject($message['subject']);

@@ -36,13 +36,13 @@ class LegacyEmailBuilder extends EmailProcessorBase {
  /**
   * Gets a message array by calling hook_mail().
   *
   * @param \Drupal\symfony_mailer\UnrenderedEmailInterface $email
   * @param \Drupal\symfony_mailer\EmailInterface $email
   *   The email to build.
   *
   * @return array
   *   Message array.
   */
  protected function getMessage(UnrenderedEmailInterface $email) {
  protected function getMessage(EmailInterface $email) {
    $module = $email->getType();
    $key = $email->getSubType();
    $message = [
Loading