diff --git a/lib/DI/ContainerConfigurator.php b/lib/DI/ContainerConfigurator.php
index 24e0e9825a..4609fbe35f 100644
--- a/lib/DI/ContainerConfigurator.php
+++ b/lib/DI/ContainerConfigurator.php
@@ -172,6 +172,7 @@ class ContainerConfigurator implements IContainerConfigurator {
$container->autowire(\MailPoet\Form\FormsRepository::class);
$container->autowire(\MailPoet\Form\Renderer::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\Date::class);
$container->autowire(\MailPoet\Form\Block\Divider::class);
diff --git a/lib/Form/Block/Base.php b/lib/Form/Block/Base.php
index a779fbba1e..0b65d6c691 100644
--- a/lib/Form/Block/Base.php
+++ b/lib/Form/Block/Base.php
@@ -6,7 +6,7 @@ use MailPoet\Form\Util\FieldNameObfuscator;
use MailPoet\Models\ModelValidator;
use MailPoet\WP\Functions as WPFunctions;
-abstract class Base {
+class Base {
/** @var FieldNameObfuscator */
private $fieldNameObfuscator;
@@ -19,7 +19,7 @@ abstract class Base {
$this->wp = $wp;
}
- protected function getInputValidation($block, $extraRules = []) {
+ public function getInputValidation($block, $extraRules = []) {
$rules = [];
if ($block['id'] === 'email') {
@@ -78,7 +78,7 @@ abstract class Base {
return join(' ', $validation);
}
- protected function renderLabel($block) {
+ public function renderLabel($block) {
$html = '';
if (
isset($block['params']['hide_label'])
@@ -106,7 +106,7 @@ abstract class Base {
return $html;
}
- protected function renderInputPlaceholder($block) {
+ public function renderInputPlaceholder($block) {
$html = '';
// if the label is displayed as a placeholder,
if (
@@ -126,7 +126,7 @@ abstract class Base {
}
// return field name depending on block data
- protected function getFieldName($block = []) {
+ public function getFieldName($block = []) {
if ((int)$block['id'] > 0) {
return 'cf_' . $block['id'];
} 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'])
&& strlen(trim($block['params']['label'])) > 0)
? trim($block['params']['label']) : '';
}
- protected function getFieldValue($block = []) {
+ public function getFieldValue($block = []) {
return (isset($block['params']['value'])
&& strlen(trim($block['params']['value'])) > 0)
? $this->wp->escAttr(trim($block['params']['value'])) : '';
}
- protected function getInputModifiers($block = []) {
+ public function getInputModifiers($block = []) {
$modifiers = [];
if (isset($block['params']['readonly']) && $block['params']['readonly']) {
diff --git a/lib/Form/Block/Checkbox.php b/lib/Form/Block/Checkbox.php
index 1e53022cf8..3bcf0d7560 100644
--- a/lib/Form/Block/Checkbox.php
+++ b/lib/Form/Block/Checkbox.php
@@ -2,24 +2,37 @@
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) {
$html = '';
- $fieldName = 'data[' . $this->getFieldName($block) . ']';
- $fieldValidation = $this->getInputValidation($block);
+ $fieldName = 'data[' . $this->baseRenderer->getFieldName($block) . ']';
+ $fieldValidation = $this->baseRenderer->getInputValidation($block);
$html .= '
';
- $html .= $this->renderLabel($block);
+ $html .= $this->baseRenderer->renderLabel($block);
$options = (!empty($block['params']['values'])
? $block['params']['values']
: []
);
- $selectedValue = self::getFieldValue($block);
+ $selectedValue = $this->baseRenderer->getFieldValue($block);
foreach ($options as $option) {
$html .= '';
}
diff --git a/lib/Form/Block/Date.php b/lib/Form/Block/Date.php
index 14bd94d224..43394f01d6 100644
--- a/lib/Form/Block/Date.php
+++ b/lib/Form/Block/Date.php
@@ -2,14 +2,19 @@
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) {
$html = '';
$html .= '
';
- $html .= $this->renderLabel($block);
+ $html .= $this->baseRenderer->renderLabel($block);
$html .= $this->renderDateSelect($block);
$html .= '
';
@@ -19,7 +24,7 @@ class Date extends Base {
private function renderDateSelect($block = []) {
$html = '';
- $fieldName = 'data[' . $this->getFieldName($block) . ']';
+ $fieldName = 'data[' . $this->baseRenderer->getFieldName($block) . ']';
$dateFormats = $this->getDateFormats();
@@ -38,24 +43,24 @@ class Date extends Base {
foreach ($dateSelectors as $dateSelector) {
if ($dateSelector === 'DD') {
$html .= '';
} else if ($dateSelector === 'MM') {
$html .= '';
} else if ($dateSelector === 'YYYY') {
$html .= '