Add WC blocks preprocessing

[MAILPOET-2286]
This commit is contained in:
Amine Ben hammou
2019-11-11 01:13:42 +01:00
committed by Jack Kitterhing
parent 5f5a254548
commit f34128d91b

View File

@ -2,9 +2,12 @@
namespace MailPoet\Newsletter\Renderer;
use MailPoet\Newsletter\Editor\LayoutHelper;
use MailPoet\Newsletter\Renderer\Blocks\Renderer as BlocksRenderer;
class Preprocessor {
const WC_HEADING_PLACEHOLDER = '[mailpet_woocommerce_heading_placeholder]';
const WC_CONTENT_PLACEHOLDER = '[mailpet_woocommerce_content_placeholder]';
/** @var BlocksRenderer */
private $blocks_renderer;
@ -23,16 +26,40 @@ class Preprocessor {
}
$blocks = [];
foreach ($content['blocks'] as $block) {
if ($block['type'] === 'automatedLatestContentLayout') {
$blocks = array_merge(
$blocks,
$this->blocks_renderer->automatedLatestContentTransformedPosts($block)
);
} else {
$blocks[] = $block;
}
$blocks = array_merge($blocks, $this->processBlock($block));
}
$content['blocks'] = $blocks;
return $content;
}
/**
* @param array $block
* @return array
*/
public function processBlock($block) {
switch ($block['type']) {
case 'automatedLatestContentLayout':
return $this->blocks_renderer->automatedLatestContentTransformedPosts($block);
case 'woocommerceHeading':
return $this->placeholder(self::WC_HEADING_PLACEHOLDER);
case 'woocommerceContent':
return $this->placeholder(self::WC_CONTENT_PLACEHOLDER);
}
return [$block];
}
/**
* @param array $block
* @return array
*/
private function placeholder($text) {
return [
LayoutHelper::row([
LayoutHelper::col([[
'type' => 'text',
'text' => $text,
]]),
]),
];
}
}