Move default core/button styles configuration to integration
[MAILPOET-5814]
This commit is contained in:
committed by
Jan Lysý
parent
0daf720d34
commit
4b55bb5bb3
@@ -149,23 +149,6 @@
|
|||||||
"typography": {
|
"typography": {
|
||||||
"fontFamily": "Arial, 'Helvetica Neue', Helvetica, sans-serif",
|
"fontFamily": "Arial, 'Helvetica Neue', Helvetica, sans-serif",
|
||||||
"fontSize": "16px"
|
"fontSize": "16px"
|
||||||
},
|
|
||||||
"blocks": {
|
|
||||||
"core/button": {
|
|
||||||
"variations": {},
|
|
||||||
"color": {
|
|
||||||
"background": "#32373c",
|
|
||||||
"text": "#ffffff"
|
|
||||||
},
|
|
||||||
"spacing": {
|
|
||||||
"padding": {
|
|
||||||
"bottom": "0.7em",
|
|
||||||
"left": "1.4em",
|
|
||||||
"right": "1.4em",
|
|
||||||
"top": "0.7em"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,7 @@ use MailPoet\EmailEditor\Engine\Renderer\Layout\FlexLayoutRenderer;
|
|||||||
class Initializer {
|
class Initializer {
|
||||||
public function initialize(): void {
|
public function initialize(): void {
|
||||||
add_action('mailpoet_blocks_renderer_initialized', [$this, 'registerCoreBlocksRenderers'], 10, 1);
|
add_action('mailpoet_blocks_renderer_initialized', [$this, 'registerCoreBlocksRenderers'], 10, 1);
|
||||||
|
add_filter('mailpoet_email_editor_theme_json', [$this, 'adjustThemeJson'], 10, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,4 +24,15 @@ class Initializer {
|
|||||||
$blocksRegistry->addBlockRenderer('core/buttons', new Renderer\Blocks\Buttons(new FlexLayoutRenderer()));
|
$blocksRegistry->addBlockRenderer('core/buttons', new Renderer\Blocks\Buttons(new FlexLayoutRenderer()));
|
||||||
$blocksRegistry->addBlockRenderer('core/button', new Renderer\Blocks\Button());
|
$blocksRegistry->addBlockRenderer('core/button', new Renderer\Blocks\Button());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adjusts the editor's theme to add blocks specific settings for core blocks.
|
||||||
|
*/
|
||||||
|
public function adjustThemeJson(\WP_Theme_JSON $editorThemeJson): \WP_Theme_JSON {
|
||||||
|
$themeJson = (string)file_get_contents(dirname(__FILE__) . '/theme.json');
|
||||||
|
$themeJson = json_decode($themeJson, true);
|
||||||
|
/** @var array $themeJson */
|
||||||
|
$editorThemeJson->merge(new \WP_Theme_JSON($themeJson, 'default'));
|
||||||
|
return $editorThemeJson;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
23
mailpoet/lib/EmailEditor/Integrations/Core/theme.json
Normal file
23
mailpoet/lib/EmailEditor/Integrations/Core/theme.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://schemas.wp.org/trunk/theme.json",
|
||||||
|
"version": 2,
|
||||||
|
"styles": {
|
||||||
|
"blocks": {
|
||||||
|
"core/button": {
|
||||||
|
"variations": {},
|
||||||
|
"color": {
|
||||||
|
"background": "#32373c",
|
||||||
|
"text": "#ffffff"
|
||||||
|
},
|
||||||
|
"spacing": {
|
||||||
|
"padding": {
|
||||||
|
"bottom": "0.7em",
|
||||||
|
"left": "1.4em",
|
||||||
|
"right": "1.4em",
|
||||||
|
"top": "0.7em"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -140,25 +140,4 @@ class RendererTest extends \MailPoetTest {
|
|||||||
verify($style)->stringContainsString('padding-top:3px;');
|
verify($style)->stringContainsString('padding-top:3px;');
|
||||||
verify($style)->stringContainsString('padding-bottom:4px;');
|
verify($style)->stringContainsString('padding-bottom:4px;');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItInlinesButtonDefaultStyles() {
|
|
||||||
$this->emailPost = new \WP_Post((object)[
|
|
||||||
'post_content' => '<!-- wp:button --><div class="wp-block-button"><a class="wp-block-button__link has-background wp-element-button">Button</a></div><!-- /wp:button -->',
|
|
||||||
]);
|
|
||||||
$rendered = $this->renderer->render($this->emailPost, 'Subject', '', 'en');
|
|
||||||
$doc = new \DOMDocument();
|
|
||||||
$doc->loadHTML($rendered['html']);
|
|
||||||
$xpath = new \DOMXPath($doc);
|
|
||||||
$nodes = $xpath->query('//td[contains(@class, "wp-block-button")]');
|
|
||||||
$button = null;
|
|
||||||
if (($nodes instanceof \DOMNodeList) && $nodes->length > 0) {
|
|
||||||
$button = $nodes->item(0);
|
|
||||||
}
|
|
||||||
$this->assertInstanceOf(\DOMElement::class, $button);
|
|
||||||
$this->assertInstanceOf(\DOMDocument::class, $button->ownerDocument);
|
|
||||||
$buttonHtml = $button->ownerDocument->saveHTML($button);
|
|
||||||
verify($buttonHtml)->stringContainsString('color:#ffffff');
|
|
||||||
verify($buttonHtml)->stringContainsString('padding:.7em 1.4em');
|
|
||||||
verify($buttonHtml)->stringContainsString('background:#32373c');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,40 @@
|
|||||||
|
<?php declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace MailPoet\EmailEditor\Integrations\Core\Renderer;
|
||||||
|
|
||||||
|
use MailPoet\EmailEditor\Engine\EmailEditor;
|
||||||
|
use MailPoet\EmailEditor\Engine\Renderer\Renderer;
|
||||||
|
use MailPoet\EmailEditor\Integrations\Core\Initializer;
|
||||||
|
|
||||||
|
class RendererTest extends \MailPoetTest {
|
||||||
|
/** @var Renderer */
|
||||||
|
private $renderer;
|
||||||
|
|
||||||
|
public function _before() {
|
||||||
|
parent::_before();
|
||||||
|
$this->renderer = $this->diContainer->get(Renderer::class);
|
||||||
|
$this->diContainer->get(EmailEditor::class)->initialize();
|
||||||
|
$this->diContainer->get(Initializer::class)->initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItInlinesButtonDefaultStyles() {
|
||||||
|
$emailPost = new \WP_Post((object)[
|
||||||
|
'post_content' => '<!-- wp:button --><div class="wp-block-button"><a class="wp-block-button__link has-background wp-element-button">Button</a></div><!-- /wp:button -->',
|
||||||
|
]);
|
||||||
|
$rendered = $this->renderer->render($emailPost, 'Subject', '', 'en');
|
||||||
|
$doc = new \DOMDocument();
|
||||||
|
$doc->loadHTML($rendered['html']);
|
||||||
|
$xpath = new \DOMXPath($doc);
|
||||||
|
$nodes = $xpath->query('//td[contains(@class, "wp-block-button")]');
|
||||||
|
$button = null;
|
||||||
|
if (($nodes instanceof \DOMNodeList) && $nodes->length > 0) {
|
||||||
|
$button = $nodes->item(0);
|
||||||
|
}
|
||||||
|
$this->assertInstanceOf(\DOMElement::class, $button);
|
||||||
|
$this->assertInstanceOf(\DOMDocument::class, $button->ownerDocument);
|
||||||
|
$buttonHtml = $button->ownerDocument->saveHTML($button);
|
||||||
|
verify($buttonHtml)->stringContainsString('color:#ffffff');
|
||||||
|
verify($buttonHtml)->stringContainsString('padding:.7em 1.4em');
|
||||||
|
verify($buttonHtml)->stringContainsString('background:#32373c');
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user