Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge release 3.19.2 into 3.20.x #268

Merged
merged 10 commits into from
Feb 19, 2024
12 changes: 6 additions & 6 deletions src/View/Helper/AbstractFormDateSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Laminas\Form\Exception;
use Locale;

use function assert;
use function extension_loaded;
use function method_exists;
use function preg_split;
Expand Down Expand Up @@ -224,12 +223,13 @@ protected function getSelectElementHelper(): FormSelect
return $this->selectHelper;
}

if (method_exists($this->view, 'plugin')) {
$selectHelper = $this->view->plugin('formselect');
assert($selectHelper instanceof FormSelect);
$this->selectHelper = $selectHelper;
if (null !== $this->view && method_exists($this->view, 'plugin')) {
$this->selectHelper = $this->view->plugin('formselect');
}

if (null === $this->selectHelper) {
$this->selectHelper = new FormSelect();
}
assert(null !== $this->selectHelper);

return $this->selectHelper;
}
Expand Down
4 changes: 2 additions & 2 deletions src/View/Helper/FormMultiCheckbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,11 @@ protected function getInputHelper(): FormInput
return $this->inputHelper;
}

if (method_exists($this->view, 'plugin')) {
if (null !== $this->view && method_exists($this->view, 'plugin')) {
$this->inputHelper = $this->view->plugin('form_input');
}

if (! $this->inputHelper instanceof FormInput) {
if (null === $this->inputHelper) {
$this->inputHelper = new FormInput();
}

Expand Down
16 changes: 9 additions & 7 deletions src/View/Helper/FormSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,16 @@ protected function renderHiddenElement(SelectElement $element): string

protected function getFormHiddenHelper(): FormHidden
{
if (! $this->formHiddenHelper) {
if (method_exists($this->view, 'plugin')) {
$this->formHiddenHelper = $this->view->plugin('formhidden');
}
if (null !== $this->formHiddenHelper) {
return $this->formHiddenHelper;
}

if (! $this->formHiddenHelper instanceof FormHidden) {
$this->formHiddenHelper = new FormHidden();
}
if (null !== $this->view && method_exists($this->view, 'plugin')) {
$this->formHiddenHelper = $this->view->plugin('formhidden');
}

if (null === $this->formHiddenHelper) {
$this->formHiddenHelper = new FormHidden();
}

return $this->formHiddenHelper;
Expand Down
10 changes: 10 additions & 0 deletions test/View/Helper/FormDateSelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ public function testGeneratesThreeSelectsWithElement(): void
self::assertStringContainsString('<select name="year"', $markup);
}

public function testGeneratesWithoutRenderer(): void
{
$element = new DateSelect('foo');
$helper = new FormDateSelectHelper();
$markup = $helper->render($element);
self::assertStringContainsString('<select name="day"', $markup);
self::assertStringContainsString('<select name="month"', $markup);
self::assertStringContainsString('<select name="year"', $markup);
}

public function testCanGenerateSelectsWithEmptyOption(): void
{
$element = new DateSelect('foo');
Expand Down
10 changes: 10 additions & 0 deletions test/View/Helper/FormSelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,16 @@ public function testHiddenElementWhenAttributeMultipleIsSet(): void
self::assertStringContainsString('<input type="hidden" name="foo" value="empty"><select', $markup);
}

public function testHiddenElementWhenNoRenderer(): void
{
$element = new SelectElement('foo');
$element->setUseHiddenElement(true);
$element->setUnselectedValue('empty');
$helper = new FormSelectHelper();
$markup = $helper->render($element);
self::assertStringContainsString('<input type="hidden" name="foo" value="empty"><select', $markup);
}

public function testRenderInputNotSelectElementRaisesException(): void
{
$element = new Element\Text('foo');
Expand Down
Loading