Add PHP constants for form block types

[MAILPOET-3297]
This commit is contained in:
Rostislav Wolny
2020-12-28 09:26:05 +01:00
committed by Veljko V
parent a018d77505
commit b3db3dbcb3
3 changed files with 35 additions and 17 deletions

View File

@@ -27,6 +27,22 @@ class FormEntity {
const STATUS_ENABLED = 'enabled';
const STATUS_DISABLED = 'disabled';
const HTML_BLOCK_TYPE = 'html';
const HEADING_BLOCK_TYPE = 'heading';
const IMAGE_BLOCK_TYPE = 'image';
const PARAGRAPH_BLOCK_TYPE = 'paragraph';
const DIVIDER_BLOCK_TYPE = 'divider';
const CHECKBOX_BLOCK_TYPE = 'checkbox';
const RADIO_BLOCK_TYPE = 'radio';
const SEGMENT_SELECTION_BLOCK_TYPE = 'segment';
const DATE_BLOCK_TYPE = 'date';
const SELECT_BLOCK_TYPE = 'select';
const TEXT_BLOCK_TYPE = 'text';
const TEXTAREA_BLOCK_TYPE = 'textarea';
const SUBMIT_BLOCK_TYPE = 'submit';
const COLUMNS_BLOCK_TYPE = 'columns';
const COLUMN_BLOCK_TYPE = 'column';
/**
* @ORM\Column(type="string")
* @var string

View File

@@ -2,6 +2,7 @@
namespace MailPoet\Form;
use MailPoet\Entities\FormEntity;
use MailPoet\Form\Block\Checkbox;
use MailPoet\Form\Block\Column;
use MailPoet\Form\Block\Columns;
@@ -101,55 +102,55 @@ class BlocksRenderer {
public function renderBlock(array $block, array $formSettings): string {
$html = '';
switch ($block['type']) {
case 'html':
case FormEntity::HTML_BLOCK_TYPE:
$html .= $this->html->render($block, $formSettings);
break;
case 'heading':
case FormEntity::HEADING_BLOCK_TYPE:
$html .= $this->heading->render($block);
break;
case 'image':
case FormEntity::IMAGE_BLOCK_TYPE:
$html .= $this->image->render($block);
break;
case 'paragraph':
case FormEntity::PARAGRAPH_BLOCK_TYPE:
$html .= $this->paragraph->render($block);
break;
case 'divider':
case FormEntity::DIVIDER_BLOCK_TYPE:
$html .= $this->divider->render($block);
break;
case 'checkbox':
case FormEntity::CHECKBOX_BLOCK_TYPE:
$html .= $this->checkbox->render($block, $formSettings);
break;
case 'radio':
case FormEntity::RADIO_BLOCK_TYPE:
$html .= $this->radio->render($block, $formSettings);
break;
case 'segment':
case FormEntity::SEGMENT_SELECTION_BLOCK_TYPE:
$html .= $this->segment->render($block, $formSettings);
break;
case 'date':
case FormEntity::DATE_BLOCK_TYPE:
$html .= $this->date->render($block, $formSettings);
break;
case 'select':
case FormEntity::SELECT_BLOCK_TYPE:
$html .= $this->select->render($block, $formSettings);
break;
case 'text':
case FormEntity::TEXT_BLOCK_TYPE:
$html .= $this->text->render($block, $formSettings);
break;
case 'textarea':
case FormEntity::TEXTAREA_BLOCK_TYPE:
$html .= $this->textarea->render($block, $formSettings);
break;
case 'submit':
case FormEntity::SUBMIT_BLOCK_TYPE:
$html .= $this->submit->render($block, $formSettings);
break;
}
@@ -159,11 +160,11 @@ class BlocksRenderer {
public function renderContainerBlock(array $block, string $content) {
$html = '';
switch ($block['type']) {
case 'columns':
case FormEntity::COLUMNS_BLOCK_TYPE:
$html .= $this->columns->render($block, $content);
break;
case 'column':
case FormEntity::COLUMN_BLOCK_TYPE:
$html .= $this->column->render($block, $content);
break;
}

View File

@@ -2,6 +2,7 @@
namespace MailPoet\Form;
use MailPoet\Entities\FormEntity;
use MailPoet\Form\Templates\FormTemplate;
use MailPoet\Form\Util\CustomFonts;
use MailPoet\Form\Util\Styles;
@@ -64,10 +65,10 @@ class Renderer {
// add honeypot for spambots
$html = ($honeypotEnabled) ? $this->renderHoneypot() : '';
foreach ($blocks as $key => $block) {
if ($block['type'] == 'submit' && $this->settings->get('captcha.type') === Captcha::TYPE_RECAPTCHA) {
if ($block['type'] === FormEntity::SUBMIT_BLOCK_TYPE && $this->settings->get('captcha.type') === Captcha::TYPE_RECAPTCHA) {
$html .= $this->renderReCaptcha();
}
if (in_array($block['type'], ['column', 'columns'])) {
if (in_array($block['type'], [FormEntity::COLUMN_BLOCK_TYPE, FormEntity::COLUMNS_BLOCK_TYPE])) {
$blocks = $block['body'] ?? [];
$html .= $this->blocksRenderer->renderContainerBlock($block, $this->renderBlocks($blocks, $formSettings, false)) . PHP_EOL;
} else {