Load mail layouts from view files if not found in the database (#4904)

Brings mail layouts more in line with the rest of the mail template pieces by loading from the relevant view files when the layout doesn't exist in the database.
This commit is contained in:
fansaien 2020-03-31 02:27:46 -06:00 committed by GitHub
parent d3596310c6
commit 9995dddc75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -71,6 +71,19 @@ class MailLayout extends Model
return array_get(self::listCodes(), $code);
}
public static function findOrMakeLayout($code)
{
$layout = self::whereCode($code)->first();
if (!$layout && View::exists($code)) {
$layout = new self;
$layout->code = $code;
$layout->fillFromView($code);
}
return $layout;
}
/**
* Loops over each mail layout and ensures the system has a layout,
* if the layout does not exist, it will create one.

View File

@ -141,7 +141,7 @@ class MailTemplate extends Model
$this->subject = array_get($sections, 'settings.subject', 'No subject');
$layoutCode = array_get($sections, 'settings.layout', 'default');
$this->layout_id = MailLayout::getIdFromCode($layoutCode);
$this->layout = MailLayout::findOrMakeLayout($layoutCode);
}
protected static function getTemplateSections($code)