Add support for heading and paragraph padding to form renderer

[MAILPOET-5714]
This commit is contained in:
Rostislav Wolny
2024-02-12 16:48:22 +01:00
committed by Aschepikov
parent 7a5241d3d3
commit 93de29b379
4 changed files with 34 additions and 0 deletions

View File

@@ -104,6 +104,13 @@ class Heading {
if (!empty($block['params']['gradient'])) {
$styles[] = "background: {$block['params']['gradient']};";
}
if (!empty($block['params']['padding']) && is_array($block['params']['padding'])) {
$top = $block['params']['padding']['top'] ?? 0;
$right = $block['params']['padding']['right'] ?? 0;
$bottom = $block['params']['padding']['bottom'] ?? 0;
$left = $block['params']['padding']['left'] ?? 0;
$styles[] = "padding:{$top} {$right} {$bottom} {$left};";
}
if (empty($styles)) {
return '';
}

View File

@@ -86,6 +86,13 @@ class Paragraph {
if (!empty($block['params']['line_height'])) {
$styles[] = 'line-height: ' . $block['params']['line_height'];
}
if (!empty($block['params']['padding']) && is_array($block['params']['padding'])) {
$top = $block['params']['padding']['top'] ?? 0;
$right = $block['params']['padding']['right'] ?? 0;
$bottom = $block['params']['padding']['bottom'] ?? 0;
$left = $block['params']['padding']['left'] ?? 0;
$styles[] = "padding:{$top} {$right} {$bottom} {$left};";
}
if (empty($styles)) {
return null;
}

View File

@@ -116,6 +116,16 @@ class HeadingTest extends \MailPoetUnitTest {
verify($html)->equals('<h2 class="mailpoet-heading mailpoet-has-font-size" style="font-size: 33px">Header</h2>');
}
public function testItShouldRenderPadding() {
$html = $this->heading->render([
'params' => [
'content' => 'Paragraph',
'padding' => ['top' => '10px', 'right' => '20px', 'bottom' => '30px', 'left' => '40px'],
],
]);
verify($html)->stringContainsString('padding:10px 20px 30px 40px;');
}
public function testItShouldRenderFontSizeWithUnit() {
$html = $this->heading->render([
'params' => [

View File

@@ -91,6 +91,16 @@ class ParagraphTest extends \MailPoetUnitTest {
verify($html)->equals('<p class="mailpoet_form_paragraph mailpoet-has-font-size" style="font-size: 33px">Paragraph</p>');
}
public function testItShouldRenderPadding() {
$html = $this->paragraph->render([
'params' => [
'content' => 'Paragraph',
'padding' => ['top' => '10px', 'right' => '20px', 'bottom' => '30px', 'left' => '40px'],
],
]);
verify($html)->stringContainsString('padding:10px 20px 30px 40px;');
}
public function testItShouldRenderFontSizeWithUnit() {
$html = $this->paragraph->render([
'params' => [