From 51d79ffabacd174bd9e24e2f1251841fb5fa37fa Mon Sep 17 00:00:00 2001 From: TimFoerster Date: Mon, 24 Sep 2018 04:49:19 +0200 Subject: [PATCH] Make auto inline brand CSS for email layouts optional (#3192) Fixes #3133. Credit to @TimFoerster. Thanks to all the reviewers from #3192. --- modules/system/classes/MailManager.php | 9 +++++++- ..._System_Mail_Layouts_Add_Options_Field.php | 21 +++++++++++++++++++ modules/system/lang/de/lang.php | 2 ++ modules/system/lang/en/lang.php | 4 +++- modules/system/models/MailLayout.php | 8 +++++++ modules/system/models/maillayout/fields.yaml | 6 ++++++ 6 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 modules/system/database/migrations/2017_10_23_000024_Db_System_Mail_Layouts_Add_Options_Field.php diff --git a/modules/system/classes/MailManager.php b/modules/system/classes/MailManager.php index a38e53d3e..5f370e2de 100644 --- a/modules/system/classes/MailManager.php +++ b/modules/system/classes/MailManager.php @@ -176,7 +176,12 @@ class MailManager $css = MailBrandSetting::renderCss(); + $disableAutoInlineCss = false; + if ($template->layout) { + + $disableAutoInlineCss = array_get($template->layout->options, 'disable_auto_inline_css', $disableAutoInlineCss); + $html = $this->renderTwig($template->layout->content_html, [ 'content' => $html, 'css' => $template->layout->content_css, @@ -186,7 +191,9 @@ class MailManager $css .= PHP_EOL . $template->layout->content_css; } - $html = (new CssToInlineStyles)->convert($html, $css); + if (!$disableAutoInlineCss) { + $html = (new CssToInlineStyles)->convert($html, $css); + } return $html; } diff --git a/modules/system/database/migrations/2017_10_23_000024_Db_System_Mail_Layouts_Add_Options_Field.php b/modules/system/database/migrations/2017_10_23_000024_Db_System_Mail_Layouts_Add_Options_Field.php new file mode 100644 index 000000000..0cac68edb --- /dev/null +++ b/modules/system/database/migrations/2017_10_23_000024_Db_System_Mail_Layouts_Add_Options_Field.php @@ -0,0 +1,21 @@ +text('options')->nullable()->after('is_locked'); + }); + } + + public function down() + { + Schema::table('system_mail_layouts', function (Blueprint $table) { + $table->dropColumn('options'); + }); + } +} diff --git a/modules/system/lang/de/lang.php b/modules/system/lang/de/lang.php index a8cf5ec6a..a6879121a 100644 --- a/modules/system/lang/de/lang.php +++ b/modules/system/lang/de/lang.php @@ -129,6 +129,8 @@ return [ 'deleting_layout' => 'Lösche Layout...', 'sending' => 'Sende Nachricht...', 'return' => 'Zurück zur Vorlagen-Liste', + 'options' => 'Optionen', + 'disable_auto_inline_css' => 'Automtische inline CSS deaktivieren', ], 'install' => [ 'project_label' => 'Mit Projekt verbinden', diff --git a/modules/system/lang/en/lang.php b/modules/system/lang/en/lang.php index 8cf813a96..043794cd5 100644 --- a/modules/system/lang/en/lang.php +++ b/modules/system/lang/en/lang.php @@ -237,7 +237,9 @@ return [ 'deleting' => 'Deleting Template...', 'deleting_layout' => 'Deleting Layout...', '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' => [ 'menu_label' => 'Mail branding', diff --git a/modules/system/models/MailLayout.php b/modules/system/models/MailLayout.php index d490571db..01273ad68 100644 --- a/modules/system/models/MailLayout.php +++ b/modules/system/models/MailLayout.php @@ -41,6 +41,13 @@ class MailLayout extends Model 'content_html' => 'required', ]; + /** + * @var array Options array + */ + protected $jsonable = [ + 'options' + ]; + public static $codeCache; public function beforeDelete() @@ -134,4 +141,5 @@ class MailLayout extends Model { return MailParser::parse(FileHelper::get(View::make($code)->getPath())); } + } diff --git a/modules/system/models/maillayout/fields.yaml b/modules/system/models/maillayout/fields.yaml index 9bbccb4eb..51656b960 100644 --- a/modules/system/models/maillayout/fields.yaml +++ b/modules/system/models/maillayout/fields.yaml @@ -39,3 +39,9 @@ secondaryTabs: size: giant tab: system::lang.mail_templates.content_text 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