Refactors Newsletters as per @badshark's comments
This commit is contained in:
25
lib/Newsletter/Renderer/Blocks/Renderer.php
Normal file
25
lib/Newsletter/Renderer/Blocks/Renderer.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php namespace MailPoet\Newsletter\Renderer\Blocks;
|
||||
|
||||
class Renderer {
|
||||
|
||||
function render($data, $column = null) {
|
||||
array_map(function ($block) use (&$blockContent, &$columns) {
|
||||
$blockContent .= $this->createElementFromBlockType($block);
|
||||
if(isset($block['blocks'])) {
|
||||
$blockContent = $this->render($block);
|
||||
}
|
||||
// vertical orientation denotes column container
|
||||
if($block['type'] === 'container' && $block['orientation'] === 'vertical') {
|
||||
$columns[] = $blockContent;
|
||||
}
|
||||
}, $data['blocks']);
|
||||
|
||||
return (isset($columns)) ? $columns : $blockContent;
|
||||
}
|
||||
|
||||
function createElementFromBlockType($block) {
|
||||
$blockClass = __NAMESPACE__ . '\\' . ucfirst($block['type']);
|
||||
return (class_exists($blockClass)) ? $blockClass::render($block) : '';
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user