Add Preprocessor for removing unwanted blocks

[MAILPOET-5591]
This commit is contained in:
Jan Lysý
2023-10-12 18:30:25 +02:00
committed by Jan Lysý
parent c1768fd0b2
commit fe5eabfe49
9 changed files with 103 additions and 10 deletions

View File

@@ -0,0 +1,17 @@
<?php declare(strict_types = 1);
namespace MailPoet\EmailEditor\Engine\Renderer\Preprocessors;
class CleanupPreprocessor implements Preprocessor {
public function preprocess(array $parsedBlocks, array $layoutStyles): array {
foreach ($parsedBlocks as $key => $block) {
// https://core.trac.wordpress.org/ticket/45312
// \WP_Block_Parser::parse_blocks() sometimes add a block with name null that can cause unexpected spaces in rendered content
// This behavior was reported as an issue, but it was closed as won't fix
if ($block['blockName'] === null) {
unset($parsedBlocks[$key]);
}
}
return array_values($parsedBlocks);
}
}

View File

@@ -3,5 +3,5 @@
namespace MailPoet\EmailEditor\Engine\Renderer\Preprocessors;
interface Preprocessor {
public function preprocess(array $parsedBlocks): array;
public function preprocess(array $parsedBlocks, array $layoutStyles): array;
}

View File

@@ -18,7 +18,7 @@ class TopLevelPreprocessor implements Preprocessor {
* But for rendering purposes it is more convenient to have them wrapped in a single column.
* This method walks through the first level of blocks and wraps non column blocks into a single column.
*/
public function preprocess(array $parsedBlocks): array {
public function preprocess(array $parsedBlocks, array $layoutStyles): array {
$wrappedParsedBlocks = [];
$nonColumnsBlocksBuffer = [];
foreach ($parsedBlocks as $block) {