-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Added ability to specify label position as an element label option #6752
Conversation
$this->helper->setLabelPosition('append'); | ||
$markup = $this->helper->render($element); | ||
$this->assertContains('<label><span>The value for foo:</span><', $markup); | ||
$this->assertContains('</label>', $markup); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test only tests if it overrides the label position, but it does not test if the default label position is respected. I encountered earlier issues where the FormRow
view helper did some unwanted caching so I think it is a good thing to make sure this does not happen again.
By adding a second element you can test for that:
public function testCanOverrideLabelPosition()
{
$fooElement = new Element('foo');
$fooElement->setOptions(array(
'label' => 'The value for foo:',
'label_options' => array(
'label_position' =>'prepend'
),
));
$barElement = new Element('bar');
$barElement->setOptions(array(
'label' => 'The value for bar:',
));
$this->helper->setLabelPosition('append');
$fooMarkup = $this->helper->render($fooElement);
$this->assertContains('<label><span>The value for foo:</span><', $fooMarkup);
$this->assertContains('</label>', $fooMarkup);
$barMarkup = $this->helper->render($barElement);
$this->assertContains('<label><', $barMarkup);
$this->assertContains('<span>The value for foo:</span></label>', $barMarkup);
}
Added ability to specify label position as an element label option Merge fixes test errors introduced in the original patch. Conflicts: library/Zend/Form/View/Helper/FormRow.php
@@ -213,7 +213,13 @@ public function render(ElementInterface $element) | |||
$labelOpen = $labelClose = $label = ''; | |||
} | |||
|
|||
switch ($this->labelPosition) { | |||
$labelPosition = $this->labelPosition; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line caused two test failures. Essentially, it was overriding lines 128-130, which were setting the value of $labelPosition
to the instance property if it had not been passed. As such, I removed it, as the value will be properly initialized by this point already.
Merged to develop for release in 2.4. |
Does exactly what it says on the tin