diff --git a/mailpoet/lib/EmailEditor/Engine/EmailApiController.php b/mailpoet/lib/EmailEditor/Engine/EmailApiController.php
index 3fb9ec4921..09891527ec 100644
--- a/mailpoet/lib/EmailEditor/Engine/EmailApiController.php
+++ b/mailpoet/lib/EmailEditor/Engine/EmailApiController.php
@@ -33,8 +33,14 @@ class EmailApiController {
public function getEmailDataSchema(): array {
return Builder::object([
'layout_styles' => Builder::object([
- 'width' => Builder::integer(),
+ 'width' => Builder::string(),
'background' => Builder::string(),
+ 'padding' => Builder::object([
+ 'bottom' => Builder::string(),
+ 'left' => Builder::string(),
+ 'right' => Builder::string(),
+ 'top' => Builder::string(),
+ ]),
]),
])->toArray();
}
diff --git a/mailpoet/lib/EmailEditor/Engine/Renderer/PreprocessManager.php b/mailpoet/lib/EmailEditor/Engine/Renderer/PreprocessManager.php
index 7af40fe9c9..605f3eceea 100644
--- a/mailpoet/lib/EmailEditor/Engine/Renderer/PreprocessManager.php
+++ b/mailpoet/lib/EmailEditor/Engine/Renderer/PreprocessManager.php
@@ -23,7 +23,7 @@ class PreprocessManager {
/**
* @param array $parsedBlocks
- * @param array{width: int, background: string, padding: array{bottom: int, left: int, right: int, top: int}} $layoutStyles
+ * @param array{width: string, background: string, padding: array{bottom: string, left: string, right: string, top: string}} $layoutStyles
* @return array
*/
public function preprocess(array $parsedBlocks, array $layoutStyles): array {
diff --git a/mailpoet/lib/EmailEditor/Engine/Renderer/Preprocessors/BlocksWidthPreprocessor.php b/mailpoet/lib/EmailEditor/Engine/Renderer/Preprocessors/BlocksWidthPreprocessor.php
index ae3917364f..aa55a72c32 100644
--- a/mailpoet/lib/EmailEditor/Engine/Renderer/Preprocessors/BlocksWidthPreprocessor.php
+++ b/mailpoet/lib/EmailEditor/Engine/Renderer/Preprocessors/BlocksWidthPreprocessor.php
@@ -7,11 +7,16 @@ namespace MailPoet\EmailEditor\Engine\Renderer\Preprocessors;
* The final width in pixels is stored in the email_attrs array because we would like to avoid changing the original attributes.
*/
class BlocksWidthPreprocessor implements Preprocessor {
+
+ const BLOCKS_WITHOUT_WIDTH = [
+ 'core/paragraph',
+ ];
+
public function preprocess(array $parsedBlocks, array $layoutStyles): array {
- $layoutWidth = $layoutStyles['width'];
+ $layoutWidth = $this->parseNumberFromStringWithPixels($layoutStyles['width']);
// Subtract padding from the width of the layout element
- $layoutWidth -= $layoutStyles['padding']['left'] ?? 0;
- $layoutWidth -= $layoutStyles['padding']['right'] ?? 0;
+ $layoutWidth -= $this->parseNumberFromStringWithPixels($layoutStyles['padding']['left'] ?? '0px');
+ $layoutWidth -= $this->parseNumberFromStringWithPixels($layoutStyles['padding']['right'] ?? '0px');
foreach ($parsedBlocks as $key => $block) {
$width = $this->convertWithToPixels($block['attrs']['width'] ?? '100%', $layoutWidth);
@@ -21,12 +26,14 @@ class BlocksWidthPreprocessor implements Preprocessor {
// Copy layout styles and update width and padding
$modifiedLayoutStyles = $layoutStyles;
- $modifiedLayoutStyles['width'] = $width;
- $modifiedLayoutStyles['padding']['left'] = $this->parseNumberFromStringWithPixels($block['attrs']['style']['spacing']['padding']['left'] ?? '0px');
- $modifiedLayoutStyles['padding']['right'] = $this->parseNumberFromStringWithPixels($block['attrs']['style']['spacing']['padding']['right'] ?? '0px');
+ $modifiedLayoutStyles['width'] = "{$width}px";
+ $modifiedLayoutStyles['padding']['left'] = $block['attrs']['style']['spacing']['padding']['left'] ?? '0px';
+ $modifiedLayoutStyles['padding']['right'] = $block['attrs']['style']['spacing']['padding']['right'] ?? '0px';
- // Set current block values and reassign it to $parsedBlocks
- $block['email_attrs']['width'] = $width;
+ // Set current block values and reassign it to $parsedBlocks, but don't set width for blocks that are not supposed to have it
+ if (!in_array($block['blockName'], self::BLOCKS_WITHOUT_WIDTH, true)) {
+ $block['email_attrs']['width'] = "{$width}px";
+ }
$block['innerBlocks'] = $this->preprocess($block['innerBlocks'], $modifiedLayoutStyles);
$parsedBlocks[$key] = $block;
}
diff --git a/mailpoet/lib/EmailEditor/Engine/Renderer/template.html b/mailpoet/lib/EmailEditor/Engine/Renderer/template.html
index fe2848b08e..fde24a63ae 100644
--- a/mailpoet/lib/EmailEditor/Engine/Renderer/template.html
+++ b/mailpoet/lib/EmailEditor/Engine/Renderer/template.html
@@ -19,8 +19,8 @@
-
-
+
+
diff --git a/mailpoet/lib/EmailEditor/Engine/StylesController.php b/mailpoet/lib/EmailEditor/Engine/StylesController.php
index 4080576cc4..7100e6656a 100644
--- a/mailpoet/lib/EmailEditor/Engine/StylesController.php
+++ b/mailpoet/lib/EmailEditor/Engine/StylesController.php
@@ -5,9 +5,9 @@ namespace MailPoet\EmailEditor\Engine;
class StylesController {
/**
* Width of the email in pixels.
- * @var int
+ * @var string
*/
- const EMAIL_WIDTH = 660;
+ const EMAIL_WIDTH = '660px';
/**
* Width of the email in pixels.
@@ -17,9 +17,9 @@ class StylesController {
/**
* Padding of the email in pixels.
- * @var int
+ * @var string
*/
- const EMAIL_PADDING = 10;
+ const EMAIL_PADDING = '10px';
/**
* Default styles applied to the email. These are going to be replaced by style settings.
@@ -43,7 +43,7 @@ class StylesController {
}
/**
- * @return array{width: int, background: string, padding: array{bottom: int, left: int, right: int, top: int}}
+ * @return array{width: string, background: string, padding: array{bottom: string, left: string, right: string, top: string}}
*/
public function getEmailLayoutStyles(): array {
return [
diff --git a/mailpoet/tests/unit/EmailEditor/Engine/Renderer/PreprocessManagerTest.php b/mailpoet/tests/unit/EmailEditor/Engine/Renderer/PreprocessManagerTest.php
index 7e4060a189..48a48e91b2 100644
--- a/mailpoet/tests/unit/EmailEditor/Engine/Renderer/PreprocessManagerTest.php
+++ b/mailpoet/tests/unit/EmailEditor/Engine/Renderer/PreprocessManagerTest.php
@@ -10,13 +10,13 @@ use MailPoet\EmailEditor\Engine\Renderer\Preprocessors\TopLevelPreprocessor;
class PreprocessManagerTest extends \MailPoetUnitTest {
public function testItCallsPreprocessorsProperly(): void {
$layoutStyles = [
- 'width' => 600,
+ 'width' => '600px',
'background' => '#ffffff',
'padding' => [
- 'bottom' => 0,
- 'left' => 0,
- 'right' => 0,
- 'top' => 0,
+ 'bottom' => '0px',
+ 'left' => '0px',
+ 'right' => '0px',
+ 'top' => '0px',
],
];
$topLevel = $this->createMock(TopLevelPreprocessor::class);
diff --git a/mailpoet/tests/unit/EmailEditor/Engine/Renderer/Preprocessors/BlocksWidthPreprocessorTest.php b/mailpoet/tests/unit/EmailEditor/Engine/Renderer/Preprocessors/BlocksWidthPreprocessorTest.php
index 32d17f4a4b..15131d8ac9 100644
--- a/mailpoet/tests/unit/EmailEditor/Engine/Renderer/Preprocessors/BlocksWidthPreprocessorTest.php
+++ b/mailpoet/tests/unit/EmailEditor/Engine/Renderer/Preprocessors/BlocksWidthPreprocessorTest.php
@@ -42,13 +42,13 @@ class BlocksWidthPreprocessorTest extends \MailPoetUnitTest {
],
],
]];
- $result = $this->preprocessor->preprocess($blocks, ['width' => 660, 'padding' => ['left' => 0, 'right' => 0]]);
+ $result = $this->preprocessor->preprocess($blocks, ['width' => '660px', 'padding' => ['left' => '0px', 'right' => '0px']]);
$result = $result[0];
- expect($result['email_attrs']['width'])->equals(660);
+ expect($result['email_attrs']['width'])->equals('660px');
expect($result['innerBlocks'])->count(3);
- expect($result['innerBlocks'][0]['email_attrs']['width'])->equals(330); // 660 * 0.5
- expect($result['innerBlocks'][1]['email_attrs']['width'])->equals(165); // 660 * 0.25
- expect($result['innerBlocks'][2]['email_attrs']['width'])->equals(100);
+ expect($result['innerBlocks'][0]['email_attrs']['width'])->equals('330px'); // 660 * 0.5
+ expect($result['innerBlocks'][1]['email_attrs']['width'])->equals('165px'); // 660 * 0.25
+ expect($result['innerBlocks'][2]['email_attrs']['width'])->equals('100px');
}
public function testItCalculatesWidthWithLayoutPadding(): void {
@@ -79,12 +79,12 @@ class BlocksWidthPreprocessorTest extends \MailPoetUnitTest {
],
],
]];
- $result = $this->preprocessor->preprocess($blocks, ['width' => 600, 'padding' => ['left' => 20, 'right' => 20]]);
+ $result = $this->preprocessor->preprocess($blocks, ['width' => '600px', 'padding' => ['left' => '20px', 'right' => '20px']]);
$result = $result[0];
expect($result['innerBlocks'])->count(3);
- expect($result['innerBlocks'][0]['email_attrs']['width'])->equals(185); // (600 - 20 - 20) * 0.33
- expect($result['innerBlocks'][1]['email_attrs']['width'])->equals(100);
- expect($result['innerBlocks'][2]['email_attrs']['width'])->equals(112); // (600 - 20 - 20) * 0.2
+ expect($result['innerBlocks'][0]['email_attrs']['width'])->equals('185px'); // (600 - 20 - 20) * 0.33
+ expect($result['innerBlocks'][1]['email_attrs']['width'])->equals('100px');
+ expect($result['innerBlocks'][2]['email_attrs']['width'])->equals('112px'); // (600 - 20 - 20) * 0.2
}
public function testItCalculatesWidthOfBlockInColumn(): void {
@@ -136,14 +136,14 @@ class BlocksWidthPreprocessorTest extends \MailPoetUnitTest {
],
],
]];
- $result = $this->preprocessor->preprocess($blocks, ['width' => 660, 'padding' => ['left' => 15, 'right' => 15]]);
+ $result = $this->preprocessor->preprocess($blocks, ['width' => '660px', 'padding' => ['left' => '15px', 'right' => '15px']]);
$innerBlocks = $result[0]['innerBlocks'];
expect($innerBlocks)->count(2);
- expect($innerBlocks[0]['email_attrs']['width'])->equals(252); // (660 - 15 - 15) * 0.4
- expect($innerBlocks[0]['innerBlocks'][0]['email_attrs']['width'])->equals(232); // paragraph: 252 - 10 - 10
- expect($innerBlocks[1]['email_attrs']['width'])->equals(378); // (660 - 15 - 15) * 0.6
- expect($innerBlocks[1]['innerBlocks'][0]['email_attrs']['width'])->equals(338); // paragraph: 378 - 25 - 15
+ expect($innerBlocks[0]['email_attrs']['width'])->equals('252px'); // (660 - 15 - 15) * 0.4
+ expect($innerBlocks[0]['innerBlocks'][0])->hasNotKey('email_attrs'); // paragraph block should not have width
+ expect($innerBlocks[1]['email_attrs']['width'])->equals('378px'); // (660 - 15 - 15) * 0.6
+ expect($innerBlocks[1]['innerBlocks'][0])->hasNotKey('email_attrs'); // paragraph block should not have width
}
public function testItAddsMissingColumnWidth(): void {
@@ -186,15 +186,15 @@ class BlocksWidthPreprocessorTest extends \MailPoetUnitTest {
],
],
]];
- $result = $this->preprocessor->preprocess($blocks, ['width' => 660, 'padding' => ['left' => 30, 'right' => 30]]);
+ $result = $this->preprocessor->preprocess($blocks, ['width' => '660px', 'padding' => ['left' => '30px', 'right' => '30px']]);
$innerBlocks = $result[0]['innerBlocks'];
expect($innerBlocks)->count(3);
- expect($innerBlocks[0]['email_attrs']['width'])->equals(200); // (660 - 30 - 30) * 0.33
- expect($innerBlocks[0]['innerBlocks'][0]['email_attrs']['width'])->equals(200); // paragraph: 200
- expect($innerBlocks[1]['email_attrs']['width'])->equals(200); // (660 - 30 - 30) * 0.33
- expect($innerBlocks[1]['innerBlocks'][0]['email_attrs']['width'])->equals(200); // paragraph: 200
- expect($innerBlocks[2]['email_attrs']['width'])->equals(200); // (660 - 30 - 30) * 0.33
- expect($innerBlocks[2]['innerBlocks'][0]['email_attrs']['width'])->equals(200); // paragraph: 200
+ expect($innerBlocks[0]['email_attrs']['width'])->equals('200px'); // (660 - 30 - 30) * 0.33
+ expect($innerBlocks[0]['innerBlocks'][0])->hasNotKey('email_attrs'); // paragraph block should not have width
+ expect($innerBlocks[1]['email_attrs']['width'])->equals('200px'); // (660 - 30 - 30) * 0.33
+ expect($innerBlocks[1]['innerBlocks'][0])->hasNotKey('email_attrs'); // paragraph block should not have width
+ expect($innerBlocks[2]['email_attrs']['width'])->equals('200px'); // (660 - 30 - 30) * 0.33
+ expect($innerBlocks[2]['innerBlocks'][0])->hasNotKey('email_attrs'); // paragraph block should not have width
}
}