Refactor form blocks to use composition instead of inheritance
[MAILPOET-2665]
This commit is contained in:
committed by
Jack Kitterhing
parent
20926d56b7
commit
c6ca749cdc
@ -172,6 +172,7 @@ class ContainerConfigurator implements IContainerConfigurator {
|
|||||||
$container->autowire(\MailPoet\Form\FormsRepository::class);
|
$container->autowire(\MailPoet\Form\FormsRepository::class);
|
||||||
$container->autowire(\MailPoet\Form\Renderer::class);
|
$container->autowire(\MailPoet\Form\Renderer::class);
|
||||||
$container->autowire(\MailPoet\Form\BlocksRenderer::class);
|
$container->autowire(\MailPoet\Form\BlocksRenderer::class);
|
||||||
|
$container->autowire(\MailPoet\Form\Block\Base::class);
|
||||||
$container->autowire(\MailPoet\Form\Block\Checkbox::class);
|
$container->autowire(\MailPoet\Form\Block\Checkbox::class);
|
||||||
$container->autowire(\MailPoet\Form\Block\Date::class);
|
$container->autowire(\MailPoet\Form\Block\Date::class);
|
||||||
$container->autowire(\MailPoet\Form\Block\Divider::class);
|
$container->autowire(\MailPoet\Form\Block\Divider::class);
|
||||||
|
@ -6,7 +6,7 @@ use MailPoet\Form\Util\FieldNameObfuscator;
|
|||||||
use MailPoet\Models\ModelValidator;
|
use MailPoet\Models\ModelValidator;
|
||||||
use MailPoet\WP\Functions as WPFunctions;
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
abstract class Base {
|
class Base {
|
||||||
|
|
||||||
/** @var FieldNameObfuscator */
|
/** @var FieldNameObfuscator */
|
||||||
private $fieldNameObfuscator;
|
private $fieldNameObfuscator;
|
||||||
@ -19,7 +19,7 @@ abstract class Base {
|
|||||||
$this->wp = $wp;
|
$this->wp = $wp;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getInputValidation($block, $extraRules = []) {
|
public function getInputValidation($block, $extraRules = []) {
|
||||||
$rules = [];
|
$rules = [];
|
||||||
|
|
||||||
if ($block['id'] === 'email') {
|
if ($block['id'] === 'email') {
|
||||||
@ -78,7 +78,7 @@ abstract class Base {
|
|||||||
return join(' ', $validation);
|
return join(' ', $validation);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function renderLabel($block) {
|
public function renderLabel($block) {
|
||||||
$html = '';
|
$html = '';
|
||||||
if (
|
if (
|
||||||
isset($block['params']['hide_label'])
|
isset($block['params']['hide_label'])
|
||||||
@ -106,7 +106,7 @@ abstract class Base {
|
|||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function renderInputPlaceholder($block) {
|
public function renderInputPlaceholder($block) {
|
||||||
$html = '';
|
$html = '';
|
||||||
// if the label is displayed as a placeholder,
|
// if the label is displayed as a placeholder,
|
||||||
if (
|
if (
|
||||||
@ -126,7 +126,7 @@ abstract class Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// return field name depending on block data
|
// return field name depending on block data
|
||||||
protected function getFieldName($block = []) {
|
public function getFieldName($block = []) {
|
||||||
if ((int)$block['id'] > 0) {
|
if ((int)$block['id'] > 0) {
|
||||||
return 'cf_' . $block['id'];
|
return 'cf_' . $block['id'];
|
||||||
} elseif (isset($block['params']['obfuscate']) && !$block['params']['obfuscate']) {
|
} elseif (isset($block['params']['obfuscate']) && !$block['params']['obfuscate']) {
|
||||||
@ -136,19 +136,19 @@ abstract class Base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getFieldLabel($block = []) {
|
public function getFieldLabel($block = []) {
|
||||||
return (isset($block['params']['label'])
|
return (isset($block['params']['label'])
|
||||||
&& strlen(trim($block['params']['label'])) > 0)
|
&& strlen(trim($block['params']['label'])) > 0)
|
||||||
? trim($block['params']['label']) : '';
|
? trim($block['params']['label']) : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getFieldValue($block = []) {
|
public function getFieldValue($block = []) {
|
||||||
return (isset($block['params']['value'])
|
return (isset($block['params']['value'])
|
||||||
&& strlen(trim($block['params']['value'])) > 0)
|
&& strlen(trim($block['params']['value'])) > 0)
|
||||||
? $this->wp->escAttr(trim($block['params']['value'])) : '';
|
? $this->wp->escAttr(trim($block['params']['value'])) : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getInputModifiers($block = []) {
|
public function getInputModifiers($block = []) {
|
||||||
$modifiers = [];
|
$modifiers = [];
|
||||||
|
|
||||||
if (isset($block['params']['readonly']) && $block['params']['readonly']) {
|
if (isset($block['params']['readonly']) && $block['params']['readonly']) {
|
||||||
|
@ -2,24 +2,37 @@
|
|||||||
|
|
||||||
namespace MailPoet\Form\Block;
|
namespace MailPoet\Form\Block;
|
||||||
|
|
||||||
class Checkbox extends Base {
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
|
class Checkbox {
|
||||||
|
|
||||||
|
/** @var Base */
|
||||||
|
private $baseRenderer;
|
||||||
|
|
||||||
|
/** @var WPFunctions */
|
||||||
|
private $wp;
|
||||||
|
|
||||||
|
public function __construct(Base $baseRenderer, WPFunctions $wp) {
|
||||||
|
$this->baseRenderer = $baseRenderer;
|
||||||
|
$this->wp = $wp;
|
||||||
|
}
|
||||||
|
|
||||||
public function render($block) {
|
public function render($block) {
|
||||||
$html = '';
|
$html = '';
|
||||||
|
|
||||||
$fieldName = 'data[' . $this->getFieldName($block) . ']';
|
$fieldName = 'data[' . $this->baseRenderer->getFieldName($block) . ']';
|
||||||
$fieldValidation = $this->getInputValidation($block);
|
$fieldValidation = $this->baseRenderer->getInputValidation($block);
|
||||||
|
|
||||||
$html .= '<p class="mailpoet_paragraph">';
|
$html .= '<p class="mailpoet_paragraph">';
|
||||||
|
|
||||||
$html .= $this->renderLabel($block);
|
$html .= $this->baseRenderer->renderLabel($block);
|
||||||
|
|
||||||
$options = (!empty($block['params']['values'])
|
$options = (!empty($block['params']['values'])
|
||||||
? $block['params']['values']
|
? $block['params']['values']
|
||||||
: []
|
: []
|
||||||
);
|
);
|
||||||
|
|
||||||
$selectedValue = self::getFieldValue($block);
|
$selectedValue = $this->baseRenderer->getFieldValue($block);
|
||||||
|
|
||||||
foreach ($options as $option) {
|
foreach ($options as $option) {
|
||||||
$html .= '<label class="mailpoet_checkbox_label">';
|
$html .= '<label class="mailpoet_checkbox_label">';
|
||||||
@ -39,7 +52,7 @@ class Checkbox extends Base {
|
|||||||
|
|
||||||
$html .= $fieldValidation;
|
$html .= $fieldValidation;
|
||||||
|
|
||||||
$html .= ' /> ' . esc_attr($option['value']);
|
$html .= ' /> ' . $this->wp->escAttr($option['value']);
|
||||||
|
|
||||||
$html .= '</label>';
|
$html .= '</label>';
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,19 @@
|
|||||||
|
|
||||||
namespace MailPoet\Form\Block;
|
namespace MailPoet\Form\Block;
|
||||||
|
|
||||||
use MailPoet\WP\Functions as WPFunctions;
|
class Date {
|
||||||
|
|
||||||
class Date extends Base {
|
/** @var Base */
|
||||||
|
private $baseRenderer;
|
||||||
|
|
||||||
|
public function __construct(Base $baseRenderer) {
|
||||||
|
$this->baseRenderer = $baseRenderer;
|
||||||
|
}
|
||||||
|
|
||||||
public function render($block) {
|
public function render($block) {
|
||||||
$html = '';
|
$html = '';
|
||||||
$html .= '<p class="mailpoet_paragraph">';
|
$html .= '<p class="mailpoet_paragraph">';
|
||||||
$html .= $this->renderLabel($block);
|
$html .= $this->baseRenderer->renderLabel($block);
|
||||||
$html .= $this->renderDateSelect($block);
|
$html .= $this->renderDateSelect($block);
|
||||||
$html .= '</p>';
|
$html .= '</p>';
|
||||||
|
|
||||||
@ -19,7 +24,7 @@ class Date extends Base {
|
|||||||
private function renderDateSelect($block = []) {
|
private function renderDateSelect($block = []) {
|
||||||
$html = '';
|
$html = '';
|
||||||
|
|
||||||
$fieldName = 'data[' . $this->getFieldName($block) . ']';
|
$fieldName = 'data[' . $this->baseRenderer->getFieldName($block) . ']';
|
||||||
|
|
||||||
$dateFormats = $this->getDateFormats();
|
$dateFormats = $this->getDateFormats();
|
||||||
|
|
||||||
@ -38,24 +43,24 @@ class Date extends Base {
|
|||||||
foreach ($dateSelectors as $dateSelector) {
|
foreach ($dateSelectors as $dateSelector) {
|
||||||
if ($dateSelector === 'DD') {
|
if ($dateSelector === 'DD') {
|
||||||
$html .= '<select class="mailpoet_date_day" ';
|
$html .= '<select class="mailpoet_date_day" ';
|
||||||
$html .= $this->getInputValidation($block, [
|
$html .= $this->baseRenderer->getInputValidation($block, [
|
||||||
'required-message' => WPFunctions::get()->__('Please select a day', 'mailpoet'),
|
'required-message' => __('Please select a day', 'mailpoet'),
|
||||||
]);
|
]);
|
||||||
$html .= 'name="' . $fieldName . '[day]" placeholder="' . __('Day', 'mailpoet') . '">';
|
$html .= 'name="' . $fieldName . '[day]" placeholder="' . __('Day', 'mailpoet') . '">';
|
||||||
$html .= $this->getDays($block);
|
$html .= $this->getDays($block);
|
||||||
$html .= '</select>';
|
$html .= '</select>';
|
||||||
} else if ($dateSelector === 'MM') {
|
} else if ($dateSelector === 'MM') {
|
||||||
$html .= '<select class="mailpoet_select mailpoet_date_month" ';
|
$html .= '<select class="mailpoet_select mailpoet_date_month" ';
|
||||||
$html .= $this->getInputValidation($block, [
|
$html .= $this->baseRenderer->getInputValidation($block, [
|
||||||
'required-message' => WPFunctions::get()->__('Please select a month', 'mailpoet'),
|
'required-message' => __('Please select a month', 'mailpoet'),
|
||||||
]);
|
]);
|
||||||
$html .= 'name="' . $fieldName . '[month]" placeholder="' . __('Month', 'mailpoet') . '">';
|
$html .= 'name="' . $fieldName . '[month]" placeholder="' . __('Month', 'mailpoet') . '">';
|
||||||
$html .= $this->getMonths($block);
|
$html .= $this->getMonths($block);
|
||||||
$html .= '</select>';
|
$html .= '</select>';
|
||||||
} else if ($dateSelector === 'YYYY') {
|
} else if ($dateSelector === 'YYYY') {
|
||||||
$html .= '<select class="mailpoet_date_year" ';
|
$html .= '<select class="mailpoet_date_year" ';
|
||||||
$html .= $this->getInputValidation($block, [
|
$html .= $this->baseRenderer->getInputValidation($block, [
|
||||||
'required-message' => WPFunctions::get()->__('Please select a year', 'mailpoet'),
|
'required-message' => __('Please select a year', 'mailpoet'),
|
||||||
]);
|
]);
|
||||||
$html .= 'name="' . $fieldName . '[year]" placeholder="' . __('Year', 'mailpoet') . '">';
|
$html .= 'name="' . $fieldName . '[year]" placeholder="' . __('Year', 'mailpoet') . '">';
|
||||||
$html .= $this->getYears($block);
|
$html .= $this->getYears($block);
|
||||||
@ -70,10 +75,10 @@ class Date extends Base {
|
|||||||
|
|
||||||
public function getDateTypes() {
|
public function getDateTypes() {
|
||||||
return [
|
return [
|
||||||
'year_month_day' => WPFunctions::get()->__('Year, month, day', 'mailpoet'),
|
'year_month_day' => __('Year, month, day', 'mailpoet'),
|
||||||
'year_month' => WPFunctions::get()->__('Year, month', 'mailpoet'),
|
'year_month' => __('Year, month', 'mailpoet'),
|
||||||
'month' => WPFunctions::get()->__('Month (January, February,...)', 'mailpoet'),
|
'month' => __('Month (January, February,...)', 'mailpoet'),
|
||||||
'year' => WPFunctions::get()->__('Year', 'mailpoet'),
|
'year' => __('Year', 'mailpoet'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,9 +91,9 @@ class Date extends Base {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
public function getMonthNames() {
|
public function getMonthNames() {
|
||||||
return [__('January', 'mailpoet'), WPFunctions::get()->__('February', 'mailpoet'), WPFunctions::get()->__('March', 'mailpoet'), WPFunctions::get()->__('April', 'mailpoet'),
|
return [__('January', 'mailpoet'), __('February', 'mailpoet'), __('March', 'mailpoet'), __('April', 'mailpoet'),
|
||||||
WPFunctions::get()->__('May', 'mailpoet'), WPFunctions::get()->__('June', 'mailpoet'), WPFunctions::get()->__('July', 'mailpoet'), WPFunctions::get()->__('August', 'mailpoet'), WPFunctions::get()->__('September', 'mailpoet'),
|
__('May', 'mailpoet'), __('June', 'mailpoet'), __('July', 'mailpoet'), __('August', 'mailpoet'), __('September', 'mailpoet'),
|
||||||
WPFunctions::get()->__('October', 'mailpoet'), WPFunctions::get()->__('November', 'mailpoet'), WPFunctions::get()->__('December', 'mailpoet'),
|
__('October', 'mailpoet'), __('November', 'mailpoet'), __('December', 'mailpoet'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,24 +2,31 @@
|
|||||||
|
|
||||||
namespace MailPoet\Form\Block;
|
namespace MailPoet\Form\Block;
|
||||||
|
|
||||||
class Radio extends Base {
|
class Radio {
|
||||||
|
|
||||||
|
/** @var Base */
|
||||||
|
private $baseRenderer;
|
||||||
|
|
||||||
|
public function __construct(Base $baseRenderer) {
|
||||||
|
$this->baseRenderer = $baseRenderer;
|
||||||
|
}
|
||||||
|
|
||||||
public function render($block) {
|
public function render($block) {
|
||||||
$html = '';
|
$html = '';
|
||||||
|
|
||||||
$fieldName = 'data[' . $this->getFieldName($block) . ']';
|
$fieldName = 'data[' . $this->baseRenderer->getFieldName($block) . ']';
|
||||||
$fieldValidation = $this->getInputValidation($block);
|
$fieldValidation = $this->baseRenderer->getInputValidation($block);
|
||||||
|
|
||||||
$html .= '<p class="mailpoet_paragraph">';
|
$html .= '<p class="mailpoet_paragraph">';
|
||||||
|
|
||||||
$html .= $this->renderLabel($block);
|
$html .= $this->baseRenderer->renderLabel($block);
|
||||||
|
|
||||||
$options = (!empty($block['params']['values'])
|
$options = (!empty($block['params']['values'])
|
||||||
? $block['params']['values']
|
? $block['params']['values']
|
||||||
: []
|
: []
|
||||||
);
|
);
|
||||||
|
|
||||||
$selectedValue = $this->getFieldValue($block);
|
$selectedValue = $this->baseRenderer->getFieldValue($block);
|
||||||
|
|
||||||
foreach ($options as $option) {
|
foreach ($options as $option) {
|
||||||
$html .= '<label class="mailpoet_radio_label">';
|
$html .= '<label class="mailpoet_radio_label">';
|
||||||
|
@ -2,17 +2,24 @@
|
|||||||
|
|
||||||
namespace MailPoet\Form\Block;
|
namespace MailPoet\Form\Block;
|
||||||
|
|
||||||
class Segment extends Base {
|
class Segment {
|
||||||
|
|
||||||
|
/** @var Base */
|
||||||
|
private $baseRenderer;
|
||||||
|
|
||||||
|
public function __construct(Base $baseRenderer) {
|
||||||
|
$this->baseRenderer = $baseRenderer;
|
||||||
|
}
|
||||||
|
|
||||||
public function render($block) {
|
public function render($block) {
|
||||||
$html = '';
|
$html = '';
|
||||||
|
|
||||||
$fieldName = 'data[' . $this->getFieldName($block) . ']';
|
$fieldName = 'data[' . $this->baseRenderer->getFieldName($block) . ']';
|
||||||
$fieldValidation = $this->getInputValidation($block);
|
$fieldValidation = $this->baseRenderer->getInputValidation($block);
|
||||||
|
|
||||||
$html .= '<p class="mailpoet_paragraph">';
|
$html .= '<p class="mailpoet_paragraph">';
|
||||||
|
|
||||||
$html .= $this->renderLabel($block);
|
$html .= $this->baseRenderer->renderLabel($block);
|
||||||
|
|
||||||
$options = (!empty($block['params']['values'])
|
$options = (!empty($block['params']['values'])
|
||||||
? $block['params']['values']
|
? $block['params']['values']
|
||||||
|
@ -2,19 +2,32 @@
|
|||||||
|
|
||||||
namespace MailPoet\Form\Block;
|
namespace MailPoet\Form\Block;
|
||||||
|
|
||||||
class Select extends Base {
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
|
class Select {
|
||||||
|
|
||||||
|
/** @var Base */
|
||||||
|
private $baseRenderer;
|
||||||
|
|
||||||
|
/** @var WPFunctions */
|
||||||
|
private $wp;
|
||||||
|
|
||||||
|
public function __construct(Base $baseRenderer, WPFunctions $wp) {
|
||||||
|
$this->baseRenderer = $baseRenderer;
|
||||||
|
$this->wp = $wp;
|
||||||
|
}
|
||||||
|
|
||||||
public function render($block) {
|
public function render($block) {
|
||||||
$html = '';
|
$html = '';
|
||||||
|
|
||||||
$fieldName = 'data[' . $this->getFieldName($block) . ']';
|
$fieldName = 'data[' . $this->baseRenderer->getFieldName($block) . ']';
|
||||||
$automationId = ($block['id'] == 'status') ? 'data-automation-id="form_status"' : '';
|
$automationId = ($block['id'] == 'status') ? 'data-automation-id="form_status"' : '';
|
||||||
$html .= '<p class="mailpoet_paragraph">';
|
$html .= '<p class="mailpoet_paragraph">';
|
||||||
$html .= $this->renderLabel($block);
|
$html .= $this->baseRenderer->renderLabel($block);
|
||||||
$html .= '<select class="mailpoet_select" name="' . $fieldName . '" ' . $automationId . '>';
|
$html .= '<select class="mailpoet_select" name="' . $fieldName . '" ' . $automationId . '>';
|
||||||
|
|
||||||
if (isset($block['params']['label_within']) && $block['params']['label_within']) {
|
if (isset($block['params']['label_within']) && $block['params']['label_within']) {
|
||||||
$label = $this->getFieldLabel($block);
|
$label = $this->baseRenderer->getFieldLabel($block);
|
||||||
if (!empty($block['params']['required'])) {
|
if (!empty($block['params']['required'])) {
|
||||||
$label .= ' *';
|
$label .= ' *';
|
||||||
}
|
}
|
||||||
@ -38,7 +51,7 @@ class Select extends Base {
|
|||||||
$isSelected = (
|
$isSelected = (
|
||||||
(isset($option['is_checked']) && $option['is_checked'])
|
(isset($option['is_checked']) && $option['is_checked'])
|
||||||
||
|
||
|
||||||
(self::getFieldValue($block) === $option['value'])
|
($this->baseRenderer->getFieldValue($block) === $option['value'])
|
||||||
) ? ' selected="selected"' : '';
|
) ? ' selected="selected"' : '';
|
||||||
|
|
||||||
$isDisabled = (!empty($option['is_disabled'])) ? ' disabled="disabled"' : '';
|
$isDisabled = (!empty($option['is_disabled'])) ? ' disabled="disabled"' : '';
|
||||||
|
@ -2,14 +2,21 @@
|
|||||||
|
|
||||||
namespace MailPoet\Form\Block;
|
namespace MailPoet\Form\Block;
|
||||||
|
|
||||||
class Submit extends Base {
|
class Submit {
|
||||||
|
|
||||||
|
/** @var Base */
|
||||||
|
private $baseRenderer;
|
||||||
|
|
||||||
|
public function __construct(Base $baseRenderer) {
|
||||||
|
$this->baseRenderer = $baseRenderer;
|
||||||
|
}
|
||||||
|
|
||||||
public function render($block) {
|
public function render($block) {
|
||||||
$html = '';
|
$html = '';
|
||||||
|
|
||||||
$html .= '<p class="mailpoet_paragraph"><input type="submit" class="mailpoet_submit" ';
|
$html .= '<p class="mailpoet_paragraph"><input type="submit" class="mailpoet_submit" ';
|
||||||
|
|
||||||
$html .= 'value="' . $this->getFieldLabel($block) . '" ';
|
$html .= 'value="' . $this->baseRenderer->getFieldLabel($block) . '" ';
|
||||||
|
|
||||||
$html .= 'data-automation-id="subscribe-submit-button" ';
|
$html .= 'data-automation-id="subscribe-submit-button" ';
|
||||||
|
|
||||||
|
@ -2,7 +2,14 @@
|
|||||||
|
|
||||||
namespace MailPoet\Form\Block;
|
namespace MailPoet\Form\Block;
|
||||||
|
|
||||||
class Text extends Base {
|
class Text {
|
||||||
|
|
||||||
|
/** @var Base */
|
||||||
|
private $baseRenderer;
|
||||||
|
|
||||||
|
public function __construct(Base $baseRenderer) {
|
||||||
|
$this->baseRenderer = $baseRenderer;
|
||||||
|
}
|
||||||
|
|
||||||
public function render($block) {
|
public function render($block) {
|
||||||
$type = 'text';
|
$type = 'text';
|
||||||
@ -14,23 +21,23 @@ class Text extends Base {
|
|||||||
|
|
||||||
$html = '<p class="mailpoet_paragraph">';
|
$html = '<p class="mailpoet_paragraph">';
|
||||||
|
|
||||||
$html .= $this->renderLabel($block);
|
$html .= $this->baseRenderer->renderLabel($block);
|
||||||
|
|
||||||
$html .= '<input type="' . $type . '" class="mailpoet_text" ';
|
$html .= '<input type="' . $type . '" class="mailpoet_text" ';
|
||||||
|
|
||||||
$html .= 'name="data[' . $this->getFieldName($block) . ']" ';
|
$html .= 'name="data[' . $this->baseRenderer->getFieldName($block) . ']" ';
|
||||||
|
|
||||||
$html .= 'title="' . $this->getFieldLabel($block) . '" ';
|
$html .= 'title="' . $this->baseRenderer->getFieldLabel($block) . '" ';
|
||||||
|
|
||||||
$html .= 'value="' . $this->getFieldValue($block) . '" ';
|
$html .= 'value="' . $this->baseRenderer->getFieldValue($block) . '" ';
|
||||||
|
|
||||||
$html .= $automationId;
|
$html .= $automationId;
|
||||||
|
|
||||||
$html .= $this->renderInputPlaceholder($block);
|
$html .= $this->baseRenderer->renderInputPlaceholder($block);
|
||||||
|
|
||||||
$html .= $this->getInputValidation($block);
|
$html .= $this->baseRenderer->getInputValidation($block);
|
||||||
|
|
||||||
$html .= $this->getInputModifiers($block);
|
$html .= $this->baseRenderer->getInputModifiers($block);
|
||||||
|
|
||||||
$html .= '/>';
|
$html .= '/>';
|
||||||
|
|
||||||
|
@ -2,27 +2,34 @@
|
|||||||
|
|
||||||
namespace MailPoet\Form\Block;
|
namespace MailPoet\Form\Block;
|
||||||
|
|
||||||
class Textarea extends Base {
|
class Textarea {
|
||||||
|
/** @var Base */
|
||||||
|
private $baseRenderer;
|
||||||
|
|
||||||
|
public function __construct(Base $baseRenderer) {
|
||||||
|
$this->baseRenderer = $baseRenderer;
|
||||||
|
}
|
||||||
|
|
||||||
public function render($block) {
|
public function render($block) {
|
||||||
$html = '';
|
$html = '';
|
||||||
|
|
||||||
$html .= '<p class="mailpoet_paragraph">';
|
$html .= '<p class="mailpoet_paragraph">';
|
||||||
|
|
||||||
$html .= $this->renderLabel($block);
|
$html .= $this->baseRenderer->renderLabel($block);
|
||||||
|
|
||||||
$lines = (isset($block['params']['lines']) ? (int)$block['params']['lines'] : 1);
|
$lines = (isset($block['params']['lines']) ? (int)$block['params']['lines'] : 1);
|
||||||
|
|
||||||
$html .= '<textarea class="mailpoet_textarea" rows="' . $lines . '" ';
|
$html .= '<textarea class="mailpoet_textarea" rows="' . $lines . '" ';
|
||||||
|
|
||||||
$html .= 'name="data[' . $this->getFieldName($block) . ']"';
|
$html .= 'name="data[' . $this->baseRenderer->getFieldName($block) . ']"';
|
||||||
|
|
||||||
$html .= $this->renderInputPlaceholder($block);
|
$html .= $this->baseRenderer->renderInputPlaceholder($block);
|
||||||
|
|
||||||
$html .= $this->getInputValidation($block);
|
$html .= $this->baseRenderer->getInputValidation($block);
|
||||||
|
|
||||||
$html .= $this->getInputModifiers($block);
|
$html .= $this->baseRenderer->getInputModifiers($block);
|
||||||
|
|
||||||
$html .= '>' . $this->getFieldValue($block) . '</textarea>';
|
$html .= '>' . $this->baseRenderer->getFieldValue($block) . '</textarea>';
|
||||||
|
|
||||||
$html .= '</p>';
|
$html .= '</p>';
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace MailPoet\Test\Form\Block;
|
namespace MailPoet\Test\Form\Block;
|
||||||
|
|
||||||
|
use MailPoet\Form\Block\Base;
|
||||||
use MailPoet\Form\Block\Select;
|
use MailPoet\Form\Block\Select;
|
||||||
use MailPoet\Form\Util\FieldNameObfuscator;
|
|
||||||
use MailPoet\Models\Subscriber;
|
use MailPoet\Models\Subscriber;
|
||||||
use MailPoet\WP\Functions;
|
use MailPoet\WP\Functions;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
@ -18,16 +18,19 @@ class SelectTest extends \MailPoetUnitTest {
|
|||||||
/** @var MockObject | Functions */
|
/** @var MockObject | Functions */
|
||||||
private $wpMock;
|
private $wpMock;
|
||||||
|
|
||||||
/** @var MockObject | FieldNameObfuscator */
|
/** @var MockObject | Base */
|
||||||
private $fieldNameObfuscatorMock;
|
private $baseMock;
|
||||||
|
|
||||||
public function _before() {
|
public function _before() {
|
||||||
parent::_before();
|
parent::_before();
|
||||||
$this->wpMock = $this->createMock(Functions::class);
|
$this->wpMock = $this->createMock(Functions::class);
|
||||||
$this->wpMock->method('escAttr')->will($this->returnArgument(0));
|
$this->wpMock->method('escAttr')->will($this->returnArgument(0));
|
||||||
$this->fieldNameObfuscatorMock = $this->createMock(FieldNameObfuscator::class);
|
$this->baseMock = $this->createMock(Base::class);
|
||||||
$this->fieldNameObfuscatorMock->method('obfuscate')->will($this->returnArgument(0));
|
$this->baseMock->method('getFieldName')->will($this->returnValue('select'));
|
||||||
$this->selectBlock = new Select($this->fieldNameObfuscatorMock, $this->wpMock);
|
$this->baseMock->method('renderLabel')->will($this->returnValue('<label></label>'));
|
||||||
|
$this->baseMock->method('getFieldLabel')->will($this->returnValue('Field label'));
|
||||||
|
$this->baseMock->method('getFieldValue')->will($this->returnValue('1'));
|
||||||
|
$this->selectBlock = new Select($this->baseMock, $this->wpMock);
|
||||||
$this->block = [
|
$this->block = [
|
||||||
'id' => 'status',
|
'id' => 'status',
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
|
Reference in New Issue
Block a user