Commit bd600228 authored by Adam Shepherd's avatar Adam Shepherd Committed by Adam Shepherd
Browse files

Issue #3271797 by AdamPS: Wrap email body

parent de064918
Loading
Loading
Loading
Loading
+1 −1
Changes for config/install/symfony_mailer.mailer_policy._.yml: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ configuration:
  mailer_url_to_absolute: {}
  mailer_inline_css: {}
  mailer_wrap_and_convert:
    rewrap: false
    plain: false
    swiftmailer: false
  email_theme:
    theme: _active_fallback
+2 −2
Changes for config/schema/symfony_mailer.schema.yml: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -215,9 +215,9 @@ symfony_mailer.email_adjuster_plugin.mailer_wrap_and_convert:
  type: mapping
  label: 'Wrap and convert'
  mapping:
    rewrap:
    plain:
      type: boolean
      label: 'Rewrap'
      label: 'Plain text'
    swiftmailer:
      type: boolean
      label: 'Emulate swiftmailer'
+2 −1
Changes for src/Plugin/EmailAdjuster/PlainOnlyEmailAdjuster.php: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -8,7 +8,8 @@ use Drupal\symfony_mailer\EmailInterface;
/**
 * Defines the Plain text only Email Adjuster.
 *
 * @EmailAdjuster(
 * @todo Disabled for now - use WrapAndConvertEmailAdjuster
 * EmailAdjuster(
 *   id = "mailer_plain_only",
 *   label = @Translation("Plain text only"),
 *   description = @Translation("Sends email as plain text only."),
+8 −10
Changes for src/Plugin/EmailAdjuster/WrapAndConvertEmailAdjuster.php: 8 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ class WrapAndConvertEmailAdjuster extends EmailAdjusterBase implements Container
    $orig_html = $email->getHtmlBody();
    $plain = $html = NULL;

    if ($orig_html) {
    if ($orig_html && !$this->configuration['plain']) {
      $html = $this->render($email, $orig_html, TRUE);
    }
    $email->setHtmlBody($html);
@@ -100,12 +100,10 @@ class WrapAndConvertEmailAdjuster extends EmailAdjusterBase implements Container
      // To wrap the plain text we need to convert to HTML to render the
      // template then convert back again. We avoid check_markup() as it would
      // convert URLs to links.
      // @todo Inefficient? Could set second parameter to `{{ body }}` then
      // search and replace with the actual body after.
      $plain = $this->render($email, _filter_autop(HTML::escape($orig_plain)), FALSE);
    }
    elseif (isset($html) && !$this->configuration['rewrap']) {
      // Reuse wrapped HTML text.
      $plain = $html;
    }
    elseif ($orig_html) {
      // Wrap plain text.
      $plain = $this->render($email, $orig_html, FALSE);
@@ -120,11 +118,11 @@ class WrapAndConvertEmailAdjuster extends EmailAdjusterBase implements Container
   * {@inheritdoc}
   */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $form['rewrap'] = [
      '#title' => $this->t('Rewrap'),
    $form['plain'] = [
      '#title' => $this->t('Plain text'),
      '#type' => 'checkbox',
      '#default_value' => $this->configuration['rewrap'],
      '#description' => $this->t('Wrap the plain text and HTML separately to allow the wrapper to be different for each.'),
      '#default_value' => $this->configuration['plain'],
      '#description' => $this->t('Send as plain text only.'),
    ];

    $form['swiftmailer'] = [
@@ -143,7 +141,7 @@ class WrapAndConvertEmailAdjuster extends EmailAdjusterBase implements Container
   */
  public function getSummary() {
    $titles = [
      'rewrap' => $this->t('Rewrap'),
      'plain' => $this->t('Plain text'),
      'swiftmailer' => $this->t('Emulate swiftmailer'),
    ];
    foreach ($this->configuration as $id => $value) {
+1 −1
Changes for symfony_mailer.install: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ function symfony_mailer_update_10006() {
    $config = $policy->getConfiguration();
    if (isset($config['mailer_html_to_text'])) {
      $config['mailer_wrap_and_convert'] = [
        'rewrap' => FALSE,
        'plain' => FALSE,
        'swiftmailer' => FALSE,
      ];
      unset($config['mailer_html_to_text']);