Files
piratepoet/lib/Newsletter/Renderer/Preprocessor.php
Amine Ben hammou 5f5a254548 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.
2019-11-28 14:07:38 +00:00

38 lines
873 B
PHP

<?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;
}
}