Move the default font family and font size settings to the theme.json

[MAILPOET-5740]
This commit is contained in:
Rostislav Wolny
2024-01-15 14:48:07 +01:00
committed by Jan Lysý
parent 07e6940162
commit c4586d60e9
8 changed files with 19 additions and 24 deletions

View File

@ -69,12 +69,11 @@ class TypographyPreprocessor implements Preprocessor {
private function setDefaultsFromTheme(array $block): array {
$themeData = $this->settingsController->getTheme()->get_data();
$contentStyles = $this->settingsController->getEmailContentStyles();
if (!($block['email_attrs']['color'] ?? '')) {
$block['email_attrs']['color'] = $themeData['styles']['color']['text'] ?? null;
}
if (!($block['email_attrs']['font-size'] ?? '')) {
$block['email_attrs']['font-size'] = $contentStyles['typography']['fontSize'];
$block['email_attrs']['font-size'] = $themeData['styles']['typography']['fontSize'];
}
return $block;
}

View File

@ -63,10 +63,6 @@ class SettingsController {
* @var array
*/
const DEFAULT_EMAIL_CONTENT_STYLES = [
'typography' => [
'fontFamily' => "Arial, 'Helvetica Neue', Helvetica, sans-serif",
'fontSize' => '16px',
],
'h1' => [
'typography' => [
'fontSize' => '32px',

View File

@ -138,6 +138,10 @@
"color": {
"background": "#ffffff",
"text": "#000000"
},
"typography": {
"fontFamily": "Arial, 'Helvetica Neue', Helvetica, sans-serif",
"fontSize": "16px"
}
}
}

View File

@ -17,7 +17,7 @@ class Heading implements BlockRenderer {
* Based on MJML <mj-text>
*/
private function getBlockWrapper(array $parsedBlock, SettingsController $settingsController): string {
$contentStyles = $settingsController->getEmailContentStyles();
$themeData = $settingsController->getTheme()->get_data();
$availableStylesheets = $settingsController->getAvailableStylesheets();
// Styles for padding need to be set on the wrapping table cell due to support in Outlook
@ -40,7 +40,7 @@ class Heading implements BlockRenderer {
}
if (!isset($styles['font-size'])) {
$styles['font-size'] = $contentStyles['typography']['fontSize'];
$styles['font-size'] = $themeData['styles']['typography']['fontSize'];
}
$styles = array_merge($styles, $this->fetchStylesFromBlockAttrs($availableStylesheets, $parsedBlock['attrs']));

View File

@ -77,19 +77,17 @@ class Image implements BlockRenderer {
/**
* This method configure the font size of the caption because it's set to 0 for the parent element to avoid unexpected white spaces
* We try to use font-size passed down from the parent element $parsedBlock['email_attrs']['font-size'], but if it's not set, we use the default font-size from the email theme.
*/
private function getCaptionStyles(SettingsController $settingsController, array $parsedBlock): string {
$contentStyles = $settingsController->getEmailContentStyles();
$themeData = $settingsController->getTheme()->get_data();
// If the alignment is set, we need to center the caption
$styles = [
'text-align' => isset($parsedBlock['attrs']['align']) ? 'center' : 'left',
];
if (isset($contentStyles['typography']['fontSize'])) {
$styles['font-size'] = $contentStyles['typography']['fontSize'];
}
$styles['font-size'] = $parsedBlock['email_attrs']['font-size'] ?? $themeData['styles']['typography']['fontSize'];
return $settingsController->convertStylesToString($styles);
}

View File

@ -18,10 +18,10 @@ class ListBlock implements BlockRenderer {
// List block does not need width specification and it can cause issues for nested lists
unset($styles['width'] );
// Use font-size and font-family from Settings when those properties are not set
$contentStyles = $settingsController->getEmailContentStyles();
// Use font-size from email theme when those properties are not set
$themeData = $settingsController->getTheme()->get_data();
if (!isset($styles['font-size'])) {
$styles['font-size'] = $contentStyles['typography']['fontSize'];
$styles['font-size'] = $themeData['styles']['typography']['fontSize'];
}
$html->set_attribute('style', $settingsController->convertStylesToString($styles));

View File

@ -16,7 +16,7 @@ class Paragraph implements BlockRenderer {
* Based on MJML <mj-text>
*/
private function getBlockWrapper(array $parsedBlock, SettingsController $settingsController): string {
$contentStyles = $settingsController->getEmailContentStyles();
$themeData = $settingsController->getTheme()->get_data();
$availableStylesheets = $settingsController->getAvailableStylesheets();
$align = $parsedBlock['attrs']['align'] ?? 'left';
@ -39,7 +39,7 @@ class Paragraph implements BlockRenderer {
}
if (!isset($styles['font-size'])) {
$styles['font-size'] = $contentStyles['typography']['fontSize'];
$styles['font-size'] = $themeData['styles']['typography']['fontSize'];
}
$styles = array_merge($styles, $this->fetchStylesFromBlockAttrs($availableStylesheets, $parsedBlock['attrs'] ?? []));

View File

@ -19,6 +19,10 @@ class TypographyPreprocessorTest extends \MailPoetUnitTest {
'color' => [
'text' => '#000000',
],
'typography' => [
'fontSize' => '13px',
'fontFamily' => 'Arial',
],
],
'settings' => [
'typography' => [
@ -38,12 +42,6 @@ class TypographyPreprocessorTest extends \MailPoetUnitTest {
],
]);
$settingsMock->method('getTheme')->willReturn($themeMock);
$settingsMock->method('getEmailContentStyles')->willReturn([
'typography' => [
'fontSize' => '13px',
'fontFamily' => 'Arial',
],
]);
$this->preprocessor = new TypographyPreprocessor($settingsMock);
}