Add PHP constants for form block types
[MAILPOET-3297]
This commit is contained in:
committed by
Veljko V
parent
a018d77505
commit
b3db3dbcb3
@@ -27,6 +27,22 @@ class FormEntity {
|
|||||||
const STATUS_ENABLED = 'enabled';
|
const STATUS_ENABLED = 'enabled';
|
||||||
const STATUS_DISABLED = 'disabled';
|
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")
|
* @ORM\Column(type="string")
|
||||||
* @var string
|
* @var string
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace MailPoet\Form;
|
namespace MailPoet\Form;
|
||||||
|
|
||||||
|
use MailPoet\Entities\FormEntity;
|
||||||
use MailPoet\Form\Block\Checkbox;
|
use MailPoet\Form\Block\Checkbox;
|
||||||
use MailPoet\Form\Block\Column;
|
use MailPoet\Form\Block\Column;
|
||||||
use MailPoet\Form\Block\Columns;
|
use MailPoet\Form\Block\Columns;
|
||||||
@@ -101,55 +102,55 @@ class BlocksRenderer {
|
|||||||
public function renderBlock(array $block, array $formSettings): string {
|
public function renderBlock(array $block, array $formSettings): string {
|
||||||
$html = '';
|
$html = '';
|
||||||
switch ($block['type']) {
|
switch ($block['type']) {
|
||||||
case 'html':
|
case FormEntity::HTML_BLOCK_TYPE:
|
||||||
$html .= $this->html->render($block, $formSettings);
|
$html .= $this->html->render($block, $formSettings);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'heading':
|
case FormEntity::HEADING_BLOCK_TYPE:
|
||||||
$html .= $this->heading->render($block);
|
$html .= $this->heading->render($block);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'image':
|
case FormEntity::IMAGE_BLOCK_TYPE:
|
||||||
$html .= $this->image->render($block);
|
$html .= $this->image->render($block);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'paragraph':
|
case FormEntity::PARAGRAPH_BLOCK_TYPE:
|
||||||
$html .= $this->paragraph->render($block);
|
$html .= $this->paragraph->render($block);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'divider':
|
case FormEntity::DIVIDER_BLOCK_TYPE:
|
||||||
$html .= $this->divider->render($block);
|
$html .= $this->divider->render($block);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'checkbox':
|
case FormEntity::CHECKBOX_BLOCK_TYPE:
|
||||||
$html .= $this->checkbox->render($block, $formSettings);
|
$html .= $this->checkbox->render($block, $formSettings);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'radio':
|
case FormEntity::RADIO_BLOCK_TYPE:
|
||||||
$html .= $this->radio->render($block, $formSettings);
|
$html .= $this->radio->render($block, $formSettings);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'segment':
|
case FormEntity::SEGMENT_SELECTION_BLOCK_TYPE:
|
||||||
$html .= $this->segment->render($block, $formSettings);
|
$html .= $this->segment->render($block, $formSettings);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'date':
|
case FormEntity::DATE_BLOCK_TYPE:
|
||||||
$html .= $this->date->render($block, $formSettings);
|
$html .= $this->date->render($block, $formSettings);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'select':
|
case FormEntity::SELECT_BLOCK_TYPE:
|
||||||
$html .= $this->select->render($block, $formSettings);
|
$html .= $this->select->render($block, $formSettings);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'text':
|
case FormEntity::TEXT_BLOCK_TYPE:
|
||||||
$html .= $this->text->render($block, $formSettings);
|
$html .= $this->text->render($block, $formSettings);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'textarea':
|
case FormEntity::TEXTAREA_BLOCK_TYPE:
|
||||||
$html .= $this->textarea->render($block, $formSettings);
|
$html .= $this->textarea->render($block, $formSettings);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'submit':
|
case FormEntity::SUBMIT_BLOCK_TYPE:
|
||||||
$html .= $this->submit->render($block, $formSettings);
|
$html .= $this->submit->render($block, $formSettings);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -159,11 +160,11 @@ class BlocksRenderer {
|
|||||||
public function renderContainerBlock(array $block, string $content) {
|
public function renderContainerBlock(array $block, string $content) {
|
||||||
$html = '';
|
$html = '';
|
||||||
switch ($block['type']) {
|
switch ($block['type']) {
|
||||||
case 'columns':
|
case FormEntity::COLUMNS_BLOCK_TYPE:
|
||||||
$html .= $this->columns->render($block, $content);
|
$html .= $this->columns->render($block, $content);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'column':
|
case FormEntity::COLUMN_BLOCK_TYPE:
|
||||||
$html .= $this->column->render($block, $content);
|
$html .= $this->column->render($block, $content);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace MailPoet\Form;
|
namespace MailPoet\Form;
|
||||||
|
|
||||||
|
use MailPoet\Entities\FormEntity;
|
||||||
use MailPoet\Form\Templates\FormTemplate;
|
use MailPoet\Form\Templates\FormTemplate;
|
||||||
use MailPoet\Form\Util\CustomFonts;
|
use MailPoet\Form\Util\CustomFonts;
|
||||||
use MailPoet\Form\Util\Styles;
|
use MailPoet\Form\Util\Styles;
|
||||||
@@ -64,10 +65,10 @@ class Renderer {
|
|||||||
// add honeypot for spambots
|
// add honeypot for spambots
|
||||||
$html = ($honeypotEnabled) ? $this->renderHoneypot() : '';
|
$html = ($honeypotEnabled) ? $this->renderHoneypot() : '';
|
||||||
foreach ($blocks as $key => $block) {
|
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();
|
$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'] ?? [];
|
$blocks = $block['body'] ?? [];
|
||||||
$html .= $this->blocksRenderer->renderContainerBlock($block, $this->renderBlocks($blocks, $formSettings, false)) . PHP_EOL;
|
$html .= $this->blocksRenderer->renderContainerBlock($block, $this->renderBlocks($blocks, $formSettings, false)) . PHP_EOL;
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user