Commit 81673070 authored by jrockowitz's avatar jrockowitz Committed by jrockowitz

Issue #2998239 by jrockowitz, cbildstein: Swift Mailer no longer working after...

Issue #2998239 by jrockowitz, cbildstein: Swift Mailer no longer working after custom email handler theme option was added
parent 76b0d574
......@@ -210,7 +210,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: false
reply_to: ''
return_path: ''
......@@ -244,7 +244,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: false
reply_to: ''
return_path: ''
......
......@@ -118,9 +118,9 @@ webform.handler.email:
twig:
type: boolean
label: 'Twig'
theme:
theme_name:
type: string
label: 'Theme'
label: 'Theme name'
debug:
type: boolean
label: 'Enable debugging'
......
......@@ -2594,3 +2594,31 @@ function webform_update_8143() {
}
_webform_update_webform_settings();
}
/**
* Issue #2998239: Swift Mailer no longer working after custom email handler theme option was added
*/
function webform_update_8144() {
$config_factory = \Drupal::configFactory();
foreach ($config_factory->listAll('webform.webform.') as $webform_config_name) {
$webform_config = $config_factory->getEditable($webform_config_name);
$data = $webform_config->getRawData();
$has_email_handler = FALSE;
foreach ($data['handlers'] as &$handler) {
if (in_array($handler['id'], ['email', 'scheduled_email'])) {
// Change 'theme' setting to 'theme_name' to prevent conflicts with
// Swift Mailer.
if (isset($handler['settings']['theme'])) {
$handler['settings']['theme_name'] = $handler['settings']['theme'];
unset($handler['settings']['theme']);
$has_email_handler = TRUE;
}
}
}
if ($has_email_handler) {
$webform_config->setData($data);
$webform_config->save();
}
}
}
......@@ -210,7 +210,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: false
reply_to: ''
return_path: ''
......@@ -244,7 +244,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: false
reply_to: ''
return_path: ''
......
......@@ -210,7 +210,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -244,7 +244,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -278,7 +278,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......
......@@ -78,9 +78,9 @@ webform.handler.scheduled_email:
twig:
type: boolean
label: 'Twig'
theme:
theme_name:
type: string
label: 'Theme'
label: 'Theme name'
debug:
type: boolean
label: 'Enable debugging'
......
......@@ -208,7 +208,7 @@ handlers:
exclude_empty_checkbox: false
html: true
attachments: false
theme: ''
theme_name: ''
twig: false
debug: true
reply_to: ''
......@@ -249,7 +249,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -289,7 +289,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -329,7 +329,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -371,7 +371,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -411,7 +411,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......
......@@ -206,7 +206,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: false
reply_to: ''
return_path: ''
......@@ -240,7 +240,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: false
reply_to: ''
return_path: ''
......
......@@ -211,7 +211,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: false
reply_to: ''
return_path: ''
......@@ -255,7 +255,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: false
reply_to: ''
return_path: ''
......
......@@ -254,7 +254,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: false
reply_to: ''
return_path: ''
......
......@@ -253,7 +253,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: false
reply_to: ''
return_path: ''
......
......@@ -223,7 +223,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: false
reply_to: ''
return_path: ''
......
......@@ -215,7 +215,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: false
reply_to: ''
return_path: ''
......
......@@ -202,7 +202,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: false
reply_to: ''
return_path: ''
......
......@@ -296,7 +296,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: false
reply_to: ''
return_path: ''
......
......@@ -196,9 +196,9 @@ class EmailWebformHandler extends WebformHandlerBase implements WebformHandlerMe
];
$settings['states'] = array_intersect_key($states, array_combine($settings['states'], $settings['states']));
// Set theme.
if ($settings['theme']) {
$settings['theme'] = $this->themeManager->getThemeName($settings['theme']);
// Set theme name.
if ($settings['theme_name']) {
$settings['theme_name'] = $this->themeManager->getThemeName($settings['theme_name']);
}
return [
......@@ -257,7 +257,7 @@ class EmailWebformHandler extends WebformHandlerBase implements WebformHandlerMe
'return_path' => '',
'sender_mail' => '',
'sender_name' => '',
'theme' => '',
'theme_name' => '',
];
}
......@@ -295,7 +295,7 @@ class EmailWebformHandler extends WebformHandlerBase implements WebformHandlerMe
'return_path' => $webform_settings->get('mail.default_return_path') ?: '',
'sender_mail' => $webform_settings->get('mail.default_sender_mail') ?: '',
'sender_name' => $webform_settings->get('mail.default_sender_name') ?: '',
'theme' => '',
'theme_name' => '',
];
return $this->defaultValues;
......@@ -702,13 +702,13 @@ class EmailWebformHandler extends WebformHandlerBase implements WebformHandlerMe
];
// Setting: Themes.
$form['additional']['theme'] = [
$form['additional']['theme_name'] = [
'#type' => 'select',
'#title' => $this->t('Theme to render this email'),
'#description' => $this->t('Select the theme that will be used to render this email.'),
'#options' => $this->themeManager->getThemeNames(),
'#parents' => ['settings', 'theme'],
'#default_value' => $this->configuration['theme'],
'#parents' => ['settings', 'theme_name'],
'#default_value' => $this->configuration['theme_name'],
];
// Development.
......@@ -813,7 +813,7 @@ class EmailWebformHandler extends WebformHandlerBase implements WebformHandlerMe
* {@inheritdoc}
*/
public function getMessage(WebformSubmissionInterface $webform_submission) {
$theme_name = $this->configuration['theme'];
$theme_name = $this->configuration['theme_name'];
// Switch to custom or default theme.
$this->themeManager->setCurrentTheme($theme_name);
......@@ -1092,25 +1092,12 @@ class EmailWebformHandler extends WebformHandlerBase implements WebformHandlerMe
'#webform_submission' => $webform_submission,
'#handler' => $this,
];
$theme_name = $this->configuration['theme'];
$theme_name = $this->configuration['theme_name'];
$message['body'] = trim((string) $this->themeManager->renderPlain($build, $theme_name));
if ($this->configuration['html']) {
switch ($this->getMailSystemSender()) {
case 'swiftmailer':
// SwiftMailer provides an HTML template which is wrapped around the
// message, therefore we need to extract the body.
// @see swiftmailer.html.twig
$dom = new \DOMDocument();
@$dom->loadHTML($message['body']);
$message['body'] = Html::serialize($dom);
// SwiftMailer looks for the $param['theme'] to be used as a custom
// swiftmailer HTML template, therefore we need
// to unset $message['theme'].
// @see \Drupal\swiftmailer\Plugin\Mail\SwiftMailer::format
unset($message['theme']);
// SwiftMailer requires that the body be valid Markup.
$message['body'] = Markup::create($message['body']);
break;
......
......@@ -18,4 +18,4 @@
<b>{{ 'Subject:'|t }}</b> {{ settings.subject }}<br />
<b>{{ 'Settings:'|t }}</b> {{ settings.html ? 'HTML' : 'Plain text'|t }} {{ settings.html and settings.attachments ? '/' : '' }}{{ settings.attachments ? 'Attachments'|t : '' }} {{ settings.twig ? '(Twig)'|t : '' }}<br />
<b>{{ 'Sent when:'|t }}</b> {% if settings.states %}{{ settings.states|join('; ') }}{% else %}{{ 'Custom'|t }}{% endif %}<br />
{% if settings.theme %}<b>{{ 'Theme:'|t }}</b> {{ settings.theme }}<br />{% endif %}
{% if settings.theme_name %}<b>{{ 'Theme:'|t }}</b> {{ settings.theme_name }}<br />{% endif %}
......@@ -610,7 +610,7 @@ handlers:
html: false
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -644,7 +644,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......
......@@ -862,7 +862,7 @@ handlers:
html: false
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -896,7 +896,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......
......@@ -1371,7 +1371,7 @@ handlers:
html: false
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -1405,7 +1405,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......
......@@ -1783,7 +1783,7 @@ handlers:
html: false
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -1817,7 +1817,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......
......@@ -205,7 +205,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -260,7 +260,7 @@ handlers:
html: false
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......
......@@ -211,7 +211,7 @@ handlers:
html: false
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......
......@@ -233,7 +233,7 @@ handlers:
html: true
attachments: true
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: reply_to@example.com
return_path: return_path@example.com
......
......@@ -203,7 +203,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -239,7 +239,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -275,7 +275,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -313,7 +313,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -349,7 +349,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......
......@@ -199,7 +199,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......
......@@ -188,7 +188,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -222,7 +222,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -256,7 +256,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -290,7 +290,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -324,7 +324,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -357,7 +357,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......
......@@ -214,7 +214,7 @@ handlers:
html: true
attachments: false
twig: true
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......
......@@ -220,7 +220,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......@@ -254,7 +254,7 @@ handlers:
html: false
attachments: false
twig: false
theme: ''
theme_name: ''
debug: true
reply_to: ''
return_path: ''
......
......@@ -294,7 +294,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: false
reply_to: ''
return_path: ''
......
......@@ -189,7 +189,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: false
reply_to: ''
return_path: ''
......
......@@ -230,7 +230,7 @@ handlers:
html: true
attachments: false
twig: false
theme: ''
theme_name: ''
debug: false
reply_to: ''
return_path: ''
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment