Create renderer for form headers
[MAILPOET-2613]
This commit is contained in:
@ -181,6 +181,7 @@ class ContainerConfigurator implements IContainerConfigurator {
|
|||||||
$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);
|
||||||
$container->autowire(\MailPoet\Form\Block\Html::class);
|
$container->autowire(\MailPoet\Form\Block\Html::class);
|
||||||
|
$container->autowire(\MailPoet\Form\Block\Heading::class);
|
||||||
$container->autowire(\MailPoet\Form\Block\Radio::class);
|
$container->autowire(\MailPoet\Form\Block\Radio::class);
|
||||||
$container->autowire(\MailPoet\Form\Block\Segment::class);
|
$container->autowire(\MailPoet\Form\Block\Segment::class);
|
||||||
$container->autowire(\MailPoet\Form\Block\Select::class);
|
$container->autowire(\MailPoet\Form\Block\Select::class);
|
||||||
|
9
lib/Form/Block/Heading.php
Normal file
9
lib/Form/Block/Heading.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MailPoet\Form\Block;
|
||||||
|
|
||||||
|
class Heading {
|
||||||
|
public function render(array $block, array $formSettings): string {
|
||||||
|
return '<h2></h2>';
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@ use MailPoet\Form\Block\Column;
|
|||||||
use MailPoet\Form\Block\Columns;
|
use MailPoet\Form\Block\Columns;
|
||||||
use MailPoet\Form\Block\Date;
|
use MailPoet\Form\Block\Date;
|
||||||
use MailPoet\Form\Block\Divider;
|
use MailPoet\Form\Block\Divider;
|
||||||
|
use MailPoet\Form\Block\Heading;
|
||||||
use MailPoet\Form\Block\Html;
|
use MailPoet\Form\Block\Html;
|
||||||
use MailPoet\Form\Block\Radio;
|
use MailPoet\Form\Block\Radio;
|
||||||
use MailPoet\Form\Block\Segment;
|
use MailPoet\Form\Block\Segment;
|
||||||
@ -52,6 +53,9 @@ class BlocksRenderer {
|
|||||||
/** @var Columns */
|
/** @var Columns */
|
||||||
private $columns;
|
private $columns;
|
||||||
|
|
||||||
|
/** @var Heading */
|
||||||
|
private $heading;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Checkbox $checkbox,
|
Checkbox $checkbox,
|
||||||
Column $column,
|
Column $column,
|
||||||
@ -59,6 +63,7 @@ class BlocksRenderer {
|
|||||||
Date $date,
|
Date $date,
|
||||||
Divider $divider,
|
Divider $divider,
|
||||||
Html $html,
|
Html $html,
|
||||||
|
Heading $heading,
|
||||||
Radio $radio,
|
Radio $radio,
|
||||||
Segment $segment,
|
Segment $segment,
|
||||||
Select $select,
|
Select $select,
|
||||||
@ -78,6 +83,7 @@ class BlocksRenderer {
|
|||||||
$this->submit = $submit;
|
$this->submit = $submit;
|
||||||
$this->text = $text;
|
$this->text = $text;
|
||||||
$this->textarea = $textarea;
|
$this->textarea = $textarea;
|
||||||
|
$this->heading = $heading;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderBlock(array $block = [], array $formSettings): string {
|
public function renderBlock(array $block = [], array $formSettings): string {
|
||||||
@ -87,6 +93,10 @@ class BlocksRenderer {
|
|||||||
$html .= $this->html->render($block, $formSettings);
|
$html .= $this->html->render($block, $formSettings);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'heading':
|
||||||
|
$html .= $this->heading->render($block, $formSettings);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'divider':
|
case 'divider':
|
||||||
$html .= $this->divider->render();
|
$html .= $this->divider->render();
|
||||||
break;
|
break;
|
||||||
|
20
tests/unit/Form/Block/HeadingTest.php
Normal file
20
tests/unit/Form/Block/HeadingTest.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MailPoet\Test\Form\Block;
|
||||||
|
|
||||||
|
use MailPoet\Form\Block\Heading;
|
||||||
|
|
||||||
|
class HeadingTest extends \MailPoetUnitTest {
|
||||||
|
/** @var Heading */
|
||||||
|
private $heading;
|
||||||
|
|
||||||
|
public function _before() {
|
||||||
|
parent::_before();
|
||||||
|
$this->heading = new Heading();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItShouldRenderHeading() {
|
||||||
|
$html = $this->heading->render([], []);
|
||||||
|
expect($html)->startsWith('<h2');
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user