Skip to content

Commit

Permalink
Merge pull request #266 from oldpec/helper-optional-renderer-concistency
Browse files Browse the repository at this point in the history
Helper optional renderer consistency
  • Loading branch information
Slamdunk authored Feb 19, 2024
2 parents c6f6c68 + 0d7ebcb commit f2ae01f
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 45 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/docs-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: docs-build
on:
release:
types: [published]
repository_dispatch:
types: docs-build
workflow_dispatch:

jobs:
build-deploy:
Expand All @@ -13,5 +12,5 @@ jobs:
- name: Build Docs
uses: laminas/documentation-theme/github-actions/docs@master
env:
"DOCS_DEPLOY_KEY": ${{ secrets.DOCS_DEPLOY_KEY }}
"GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }}
DEPLOY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52 changes: 26 additions & 26 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

0 comments on commit f2ae01f

Please sign in to comment.