Move the default font family and font size settings to the theme.json
[MAILPOET-5740]
This commit is contained in:
committed by
Jan Lysý
parent
07e6940162
commit
c4586d60e9
@ -69,12 +69,11 @@ class TypographyPreprocessor implements Preprocessor {
|
|||||||
|
|
||||||
private function setDefaultsFromTheme(array $block): array {
|
private function setDefaultsFromTheme(array $block): array {
|
||||||
$themeData = $this->settingsController->getTheme()->get_data();
|
$themeData = $this->settingsController->getTheme()->get_data();
|
||||||
$contentStyles = $this->settingsController->getEmailContentStyles();
|
|
||||||
if (!($block['email_attrs']['color'] ?? '')) {
|
if (!($block['email_attrs']['color'] ?? '')) {
|
||||||
$block['email_attrs']['color'] = $themeData['styles']['color']['text'] ?? null;
|
$block['email_attrs']['color'] = $themeData['styles']['color']['text'] ?? null;
|
||||||
}
|
}
|
||||||
if (!($block['email_attrs']['font-size'] ?? '')) {
|
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;
|
return $block;
|
||||||
}
|
}
|
||||||
|
@ -63,10 +63,6 @@ class SettingsController {
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
const DEFAULT_EMAIL_CONTENT_STYLES = [
|
const DEFAULT_EMAIL_CONTENT_STYLES = [
|
||||||
'typography' => [
|
|
||||||
'fontFamily' => "Arial, 'Helvetica Neue', Helvetica, sans-serif",
|
|
||||||
'fontSize' => '16px',
|
|
||||||
],
|
|
||||||
'h1' => [
|
'h1' => [
|
||||||
'typography' => [
|
'typography' => [
|
||||||
'fontSize' => '32px',
|
'fontSize' => '32px',
|
||||||
|
@ -138,6 +138,10 @@
|
|||||||
"color": {
|
"color": {
|
||||||
"background": "#ffffff",
|
"background": "#ffffff",
|
||||||
"text": "#000000"
|
"text": "#000000"
|
||||||
|
},
|
||||||
|
"typography": {
|
||||||
|
"fontFamily": "Arial, 'Helvetica Neue', Helvetica, sans-serif",
|
||||||
|
"fontSize": "16px"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ class Heading implements BlockRenderer {
|
|||||||
* Based on MJML <mj-text>
|
* Based on MJML <mj-text>
|
||||||
*/
|
*/
|
||||||
private function getBlockWrapper(array $parsedBlock, SettingsController $settingsController): string {
|
private function getBlockWrapper(array $parsedBlock, SettingsController $settingsController): string {
|
||||||
$contentStyles = $settingsController->getEmailContentStyles();
|
$themeData = $settingsController->getTheme()->get_data();
|
||||||
$availableStylesheets = $settingsController->getAvailableStylesheets();
|
$availableStylesheets = $settingsController->getAvailableStylesheets();
|
||||||
|
|
||||||
// Styles for padding need to be set on the wrapping table cell due to support in Outlook
|
// 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'])) {
|
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']));
|
$styles = array_merge($styles, $this->fetchStylesFromBlockAttrs($availableStylesheets, $parsedBlock['attrs']));
|
||||||
|
@ -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
|
* 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 {
|
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
|
// If the alignment is set, we need to center the caption
|
||||||
$styles = [
|
$styles = [
|
||||||
'text-align' => isset($parsedBlock['attrs']['align']) ? 'center' : 'left',
|
'text-align' => isset($parsedBlock['attrs']['align']) ? 'center' : 'left',
|
||||||
];
|
];
|
||||||
|
|
||||||
if (isset($contentStyles['typography']['fontSize'])) {
|
$styles['font-size'] = $parsedBlock['email_attrs']['font-size'] ?? $themeData['styles']['typography']['fontSize'];
|
||||||
$styles['font-size'] = $contentStyles['typography']['fontSize'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $settingsController->convertStylesToString($styles);
|
return $settingsController->convertStylesToString($styles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,10 +18,10 @@ class ListBlock implements BlockRenderer {
|
|||||||
// List block does not need width specification and it can cause issues for nested lists
|
// List block does not need width specification and it can cause issues for nested lists
|
||||||
unset($styles['width'] );
|
unset($styles['width'] );
|
||||||
|
|
||||||
// Use font-size and font-family from Settings when those properties are not set
|
// Use font-size from email theme when those properties are not set
|
||||||
$contentStyles = $settingsController->getEmailContentStyles();
|
$themeData = $settingsController->getTheme()->get_data();
|
||||||
if (!isset($styles['font-size'])) {
|
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));
|
$html->set_attribute('style', $settingsController->convertStylesToString($styles));
|
||||||
|
@ -16,7 +16,7 @@ class Paragraph implements BlockRenderer {
|
|||||||
* Based on MJML <mj-text>
|
* Based on MJML <mj-text>
|
||||||
*/
|
*/
|
||||||
private function getBlockWrapper(array $parsedBlock, SettingsController $settingsController): string {
|
private function getBlockWrapper(array $parsedBlock, SettingsController $settingsController): string {
|
||||||
$contentStyles = $settingsController->getEmailContentStyles();
|
$themeData = $settingsController->getTheme()->get_data();
|
||||||
$availableStylesheets = $settingsController->getAvailableStylesheets();
|
$availableStylesheets = $settingsController->getAvailableStylesheets();
|
||||||
|
|
||||||
$align = $parsedBlock['attrs']['align'] ?? 'left';
|
$align = $parsedBlock['attrs']['align'] ?? 'left';
|
||||||
@ -39,7 +39,7 @@ class Paragraph implements BlockRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($styles['font-size'])) {
|
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'] ?? []));
|
$styles = array_merge($styles, $this->fetchStylesFromBlockAttrs($availableStylesheets, $parsedBlock['attrs'] ?? []));
|
||||||
|
@ -19,6 +19,10 @@ class TypographyPreprocessorTest extends \MailPoetUnitTest {
|
|||||||
'color' => [
|
'color' => [
|
||||||
'text' => '#000000',
|
'text' => '#000000',
|
||||||
],
|
],
|
||||||
|
'typography' => [
|
||||||
|
'fontSize' => '13px',
|
||||||
|
'fontFamily' => 'Arial',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'settings' => [
|
'settings' => [
|
||||||
'typography' => [
|
'typography' => [
|
||||||
@ -38,12 +42,6 @@ class TypographyPreprocessorTest extends \MailPoetUnitTest {
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
$settingsMock->method('getTheme')->willReturn($themeMock);
|
$settingsMock->method('getTheme')->willReturn($themeMock);
|
||||||
$settingsMock->method('getEmailContentStyles')->willReturn([
|
|
||||||
'typography' => [
|
|
||||||
'fontSize' => '13px',
|
|
||||||
'fontFamily' => 'Arial',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
$this->preprocessor = new TypographyPreprocessor($settingsMock);
|
$this->preprocessor = new TypographyPreprocessor($settingsMock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user