Skip to content

Commit ffa4f96

Browse files
committed
Don't save page template if html is empty and show error message
1 parent 397849c commit ffa4f96

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

admin/controller/editor/editor.php

+19-15
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ function save() {
504504
}
505505
}
506506

507-
$content = $this->request->post['html'] ?? false;
507+
$html = $this->request->post['html'] ?? false;
508508
$elements = $this->request->post['elements'] ?? false;
509509
$setTemplate = $this->request->post['setTemplate'] ?? false;
510510

@@ -517,8 +517,8 @@ function save() {
517517
$themeFolder = $this->getThemeFolder();
518518

519519
if ($startTemplateUrl) {
520-
$content = file_get_contents($themeFolder . DS . $startTemplateUrl);
521-
$content = preg_replace('@<base href[^>]+>@', '<base href="' . $baseUrl . '">', $content);
520+
$html = file_get_contents($themeFolder . DS . $startTemplateUrl);
521+
$html = preg_replace('@<base href[^>]+>@', '<base href="' . $baseUrl . '">', $html);
522522
}
523523

524524
if (! $url) {
@@ -572,21 +572,25 @@ function save() {
572572
$fileName = $themeFolder . DS . ($folder ? $folder . DS : '') . $file;
573573
}
574574

575-
$globalOptions = [];
576-
//keep css inline for email templates
577-
if (strpos($fileName, '/email/') !== false) {
578-
$globalOptions['inline-css'] = true;
579-
}
575+
if ($html) {
576+
if (file_put_contents($fileName, $html)) {
577+
$globalOptions = [];
578+
//keep css inline for email templates
579+
if (strpos($fileName, '/email/') !== false) {
580+
$globalOptions['inline-css'] = true;
581+
}
580582

581-
$content = $this->saveGlobalElements($content, $globalOptions);
583+
$html = $this->saveGlobalElements($html, $globalOptions);
582584

583-
if (file_put_contents($fileName, $content)) {
584-
$success = true;
585-
$text .= __('File saved!');
586-
} else {
587-
if (!is_writable($fileName)) {
588-
$text .= sprintf(__('%s is not writable!'), $fileName);
585+
$success = true;
586+
$text .= __('File saved!');
587+
} else {
588+
if (! is_writable($fileName)) {
589+
$text .= sprintf(__('%s is not writable!'), $fileName);
590+
}
589591
}
592+
} else {
593+
$text .= sprintf(__('Page html empty!'), $fileName);
590594
}
591595

592596
$cssFile = DS . 'css' . DS . 'custom.css';

0 commit comments

Comments
 (0)