Commit 82b7643f authored by Adam Shepherd's avatar Adam Shepherd
Browse files

Issue #3278050 by AdamPS: Tidy up EmailInterface body functions

parent 358aff50
Loading
Loading
Loading
Loading
+3 −3
Changes for modules/symfony_mailer_bc/src/MailManagerReplacement.php: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -154,16 +154,16 @@ class MailManagerReplacement extends MailManager {
    if (is_array($message['body'])) {
      foreach ($message['body'] as $part) {
        if ($part instanceof MarkupInterface) {
          $content = ['#markup' => $part];
          $body[] = ['#markup' => $part];
        }
        else {
          $content = [
          $body[] = [
            '#type' => 'processed_text',
            '#text' => $part,
          ];
        }
        $email->appendBody($content);
      }
      $email->setBody($body ?? []);
    }
    else {
      $email->setHtmlBody($message['body']);
+1 −1
Changes for modules/symfony_mailer_bc/src/Plugin/EmailBuilder/ContactEmailBuilderBase.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ class ContactEmailBuilderBase extends EmailBuilderBase {
    $sender = $email->getParam('sender');
    $contact_message = $email->getParam('contact_message');

    $email->appendBodyEntity($contact_message, 'mail')
    $email->setBodyEntity($contact_message, 'mail')
      ->addLibrary('symfony_mailer_bc/contact')
      ->setVariable('subject', $contact_message->getSubject())
      ->setVariable('site_name', \Drupal::config('system.site')->get('name'))
+1 −1
Changes for modules/symfony_mailer_bc/src/Plugin/EmailBuilder/SimplenewsNewsletterEmailBuilder.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ class SimplenewsNewsletterEmailBuilder extends SimplenewsEmailBuilderBase {
   */
  public function build(EmailInterface $email) {
    parent::build($email);
    $email->appendBodyEntity($email->getParam('issue'), 'email_html')
    $email->setBodyEntity($email->getParam('issue'), 'email_html')
      ->addTextHeader('Precedence', 'bulk')
      ->setVariable('opt_out_hidden', !$email->getEntity()->isAccessible());

+2 −12
Changes for src/Email.php: 2 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -272,21 +272,11 @@ class Email implements InternalEmailInterface {
  /**
   * {@inheritdoc}
   */
  public function appendBody($body) {
    $this->valid(self::PHASE_PRE_RENDER);
    $name = 'n' . count($this->body);
    $this->body[$name] = $body;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function appendBodyEntity(EntityInterface $entity, $view_mode = 'full') {
  public function setBodyEntity(EntityInterface $entity, $view_mode = 'full') {
    $this->valid(self::PHASE_PRE_RENDER);
    $build = $this->entityTypeManager->getViewBuilder($entity->getEntityTypeId())
      ->view($entity, $view_mode);
    $this->appendBody($build);
    $this->setBody($build);
    return $this;
  }

+2 −17
Changes for src/EmailInterface.php: 2 added lines, 17 removed lines.
Original line number Diff line number Diff line
@@ -180,22 +180,7 @@ interface EmailInterface extends BaseEmailInterface {
  public function setBody($body);

  /**
   * Appends content to the email body array.
   *
   * Valid: before rendering.
   *
   * @param $body
   *   Unrendered body part to append to the existing body array.
   *
   * @return $this
   */
  public function appendBody($body);

  /**
   * Appends an entity to the email body array.
   *
   * WARNING: rendering as a trusted user can expose private information . Call
   * ::setAccount() unless you are sure this cannot occur.
   * Builds the email body array from an entity.
   *
   * Valid: before rendering.
   *
@@ -206,7 +191,7 @@ interface EmailInterface extends BaseEmailInterface {
   *
   * @return $this
   */
  public function appendBodyEntity(EntityInterface $entity, $view_mode = 'full');
  public function setBodyEntity(EntityInterface $entity, $view_mode = 'full');

  /**
   * Gets the unrendered email body array.
Loading