Refactor form blocks to use composition instead of inheritance

[MAILPOET-2665]
This commit is contained in:
Rostislav Wolny
2020-02-10 14:32:39 +01:00
committed by Jack Kitterhing
parent 20926d56b7
commit c6ca749cdc
11 changed files with 138 additions and 68 deletions

View File

@@ -2,27 +2,34 @@
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) {
$html = '';
$html .= '<p class="mailpoet_paragraph">';
$html .= $this->renderLabel($block);
$html .= $this->baseRenderer->renderLabel($block);
$lines = (isset($block['params']['lines']) ? (int)$block['params']['lines'] : 1);
$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>';