Skip to content

Loading…

Update library/Zend/Form/View/Helper/FormRow.php #3345

Closed
wants to merge 3 commits into from

2 participants

@rb-cohen

In FormRow::__invoke(), setRenderErrors is always set to true.

I was trying to disable inline error messages in the form, but still use the FormCollection helper. I tried this:

$formRow = $this->getServiceLocator()->get('viewhelpermanager')->get('formrow');
$formRow->setRenderErrors(false);

$formCollection = $this->getServiceLocator()->get('viewhelpermanager')->get('formcollection');
$formCollection->setElementHelper($formRow);
$formHtml = $formCollection->render($form);

But renderErrors was always set to true again by __invoke();

The suggested fix didn't break any unit tests?

@rb-cohen rb-cohen Update library/Zend/Form/View/Helper/FormRow.php
setRenderErrors is not always set to true, incase it has been set to false already.
8942ff8
@weierophinney
Zend Framework member

Looks reasonable -- can you create a unit test for the new behavior, though, please?

@rb-cohen

I could only think of mocking the setRenderErrors method, let me know if there is a better way of doing it and I'll refactor.

@weierophinney weierophinney added a commit that referenced this pull request
@weierophinney weierophinney [#3345] CS fixes
- Trailing whitespace
28f4394
@weierophinney weierophinney was assigned
@weierophinney weierophinney added a commit that closed this pull request
@weierophinney weierophinney Merge branch 'hotfix/3345'
Close #3345
e8698c3
@weierophinney
Zend Framework member

Perfect -- thanks, @rb-cohen !

@youngguns-nl youngguns-nl pushed a commit to youngguns-nl/zf2 that referenced this pull request
@weierophinney weierophinney Merge branch 'hotfix/3345' into develop
Close #3345
2d8f631
@ghost Unknown pushed a commit that referenced this pull request
@weierophinney weierophinney [#3345] CS fixes
- Trailing whitespace
bb6658a
@ghost Unknown pushed a commit that referenced this pull request
@weierophinney weierophinney Merge branch 'hotfix/3345'
Close #3345
33a9593
@ghost Unknown pushed a commit that referenced this pull request
@weierophinney weierophinney Merge branch 'hotfix/3345' into develop
Close #3345
b860562
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 4, 2013
  1. @rb-cohen

    Update library/Zend/Form/View/Helper/FormRow.php

    rb-cohen committed
    setRenderErrors is not always set to true, incase it has been set to false already.
  2. @rb-cohen
  3. @rb-cohen

    Revert formatting

    rb-cohen committed
Showing with 24 additions and 2 deletions.
  1. +4 −2 library/Zend/Form/View/Helper/FormRow.php
  2. +20 −0 tests/ZendTest/Form/View/Helper/FormRowTest.php
View
6 library/Zend/Form/View/Helper/FormRow.php
@@ -160,7 +160,7 @@ public function render(ElementInterface $element)
* @param bool $renderErrors
* @return string|FormRow
*/
- public function __invoke(ElementInterface $element = null, $labelPosition = null, $renderErrors = true)
+ public function __invoke(ElementInterface $element = null, $labelPosition = null, $renderErrors = null)
{
if (!$element) {
return $this;
@@ -170,7 +170,9 @@ public function __invoke(ElementInterface $element = null, $labelPosition = null
$this->setLabelPosition($labelPosition);
}
- $this->setRenderErrors($renderErrors);
+ if($renderErrors !== null){
+ $this->setRenderErrors($renderErrors);
+ }
return $this->render($element);
}
View
20 tests/ZendTest/Form/View/Helper/FormRowTest.php
@@ -319,4 +319,24 @@ public function testErrorShowTwice()
$markup = $this->helper->__invoke($element);
$this->assertEquals(2, count(explode("<ul><li>The input does not appear to be a valid date</li></ul>", $markup)));
}
+
+ public function testInvokeWithNoRenderErrors()
+ {
+ $mock = $this->getMock(get_class($this->helper), array('setRenderErrors'));
+ $mock->expects($this->never())
+ ->method('setRenderErrors');
+
+ $mock->__invoke(new Element('foo'));
+ }
+
+ public function testInvokeWithRenderErrorsTrue()
+ {
+ $mock = $this->getMock(get_class($this->helper), array('setRenderErrors'));
+ $mock->expects($this->once())
+ ->method('setRenderErrors')
+ ->with(true);
+
+ $mock->__invoke(new Element('foo'), null, true);
+ }
+
}
Something went wrong with that request. Please try again.