Move preprocessing logic into Preprocessor class
[MAILPOET-2286] Additional preprocessing logic is needed to handle WooCommerce blocks, so instead of making the Renderer class even bigger, I am creating a new Preprocessor class. I wanted to move the `addMailpoetLogoContentBlock` logic as well but it will break tests and require a lot of refactor to fix them so I am leaving it here for now.
This commit is contained in:
committed by
Jack Kitterhing
parent
9e27afc994
commit
5f5a254548
38
lib/Newsletter/Renderer/Preprocessor.php
Normal file
38
lib/Newsletter/Renderer/Preprocessor.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Newsletter\Renderer;
|
||||
|
||||
use MailPoet\Newsletter\Renderer\Blocks\Renderer as BlocksRenderer;
|
||||
|
||||
class Preprocessor {
|
||||
|
||||
/** @var BlocksRenderer */
|
||||
private $blocks_renderer;
|
||||
|
||||
public function __construct(BlocksRenderer $blocks_renderer) {
|
||||
$this->blocks_renderer = $blocks_renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $content
|
||||
* @return array
|
||||
*/
|
||||
public function process($content) {
|
||||
if (!array_key_exists('blocks', $content)) {
|
||||
return $content;
|
||||
}
|
||||
$blocks = [];
|
||||
foreach ($content['blocks'] as $block) {
|
||||
if ($block['type'] === 'automatedLatestContentLayout') {
|
||||
$blocks = array_merge(
|
||||
$blocks,
|
||||
$this->blocks_renderer->automatedLatestContentTransformedPosts($block)
|
||||
);
|
||||
} else {
|
||||
$blocks[] = $block;
|
||||
}
|
||||
}
|
||||
$content['blocks'] = $blocks;
|
||||
return $content;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user