Add Preprocessor for removing unwanted blocks
[MAILPOET-5591]
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
|
@@ -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) {
|
||||
|
Reference in New Issue
Block a user