Make auto inline brand CSS for email layouts optional (#3192)

Fixes #3133. Credit to @TimFoerster. Thanks to all the reviewers from #3192.
This commit is contained in:
TimFoerster 2018-09-24 04:49:19 +02:00 committed by Luke Towers
parent a03a76ee52
commit 51d79ffaba
6 changed files with 48 additions and 2 deletions

View File

@ -176,7 +176,12 @@ class MailManager
$css = MailBrandSetting::renderCss(); $css = MailBrandSetting::renderCss();
$disableAutoInlineCss = false;
if ($template->layout) { if ($template->layout) {
$disableAutoInlineCss = array_get($template->layout->options, 'disable_auto_inline_css', $disableAutoInlineCss);
$html = $this->renderTwig($template->layout->content_html, [ $html = $this->renderTwig($template->layout->content_html, [
'content' => $html, 'content' => $html,
'css' => $template->layout->content_css, 'css' => $template->layout->content_css,
@ -186,7 +191,9 @@ class MailManager
$css .= PHP_EOL . $template->layout->content_css; $css .= PHP_EOL . $template->layout->content_css;
} }
$html = (new CssToInlineStyles)->convert($html, $css); if (!$disableAutoInlineCss) {
$html = (new CssToInlineStyles)->convert($html, $css);
}
return $html; return $html;
} }

View File

@ -0,0 +1,21 @@
<?php
use October\Rain\Database\Schema\Blueprint;
use October\Rain\Database\Updates\Migration;
class DbSystemMailLayoutsAddOptionsField extends Migration
{
public function up()
{
Schema::table('system_mail_layouts', function (Blueprint $table) {
$table->text('options')->nullable()->after('is_locked');
});
}
public function down()
{
Schema::table('system_mail_layouts', function (Blueprint $table) {
$table->dropColumn('options');
});
}
}

View File

@ -129,6 +129,8 @@ return [
'deleting_layout' => 'Lösche Layout...', 'deleting_layout' => 'Lösche Layout...',
'sending' => 'Sende Nachricht...', 'sending' => 'Sende Nachricht...',
'return' => 'Zurück zur Vorlagen-Liste', 'return' => 'Zurück zur Vorlagen-Liste',
'options' => 'Optionen',
'disable_auto_inline_css' => 'Automtische inline CSS deaktivieren',
], ],
'install' => [ 'install' => [
'project_label' => 'Mit Projekt verbinden', 'project_label' => 'Mit Projekt verbinden',

View File

@ -237,7 +237,9 @@ return [
'deleting' => 'Deleting Template...', 'deleting' => 'Deleting Template...',
'deleting_layout' => 'Deleting Layout...', 'deleting_layout' => 'Deleting Layout...',
'sending' => 'Sending test message...', 'sending' => 'Sending test message...',
'return' => 'Return to template list' 'return' => 'Return to template list',
'options' => 'Options',
'disable_auto_inline_css' => 'Disable automatic inline CSS'
], ],
'mail_brand' => [ 'mail_brand' => [
'menu_label' => 'Mail branding', 'menu_label' => 'Mail branding',

View File

@ -41,6 +41,13 @@ class MailLayout extends Model
'content_html' => 'required', 'content_html' => 'required',
]; ];
/**
* @var array Options array
*/
protected $jsonable = [
'options'
];
public static $codeCache; public static $codeCache;
public function beforeDelete() public function beforeDelete()
@ -134,4 +141,5 @@ class MailLayout extends Model
{ {
return MailParser::parse(FileHelper::get(View::make($code)->getPath())); return MailParser::parse(FileHelper::get(View::make($code)->getPath()));
} }
} }

View File

@ -39,3 +39,9 @@ secondaryTabs:
size: giant size: giant
tab: system::lang.mail_templates.content_text tab: system::lang.mail_templates.content_text
stretch: true stretch: true
options[disable_auto_inline_css]:
label: system::lang.mail_templates.disable_auto_inline_css
type: checkbox
tab: system::lang.mail_templates.options
default: false