Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge pull request #6752 from carnage/label-position-option
Browse files Browse the repository at this point in the history
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
  • Loading branch information
weierophinney committed Feb 23, 2015
2 parents 7b1320b + b209e57 commit 7f524a3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions library/Zend/Form/View/Helper/FormRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ public function render(ElementInterface $element, $labelPosition = null)
$labelOpen = $labelClose = $label = '';
}

if ($element instanceof LabelAwareInterface && $element->getLabelOption('label_position')) {
$labelPosition = $element->getLabelOption('label_position');
}

switch ($labelPosition) {
case self::LABEL_PREPEND:
$markup = $labelOpen . $label . $elementString . $labelClose;
Expand Down
26 changes: 26 additions & 0 deletions tests/ZendTest/Form/View/Helper/FormRowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,32 @@ public function testCanCreateLabelValueAfterInput()
$this->assertContains('</label>', $markup);
}

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 bar:</span></label>', $barMarkup);
}

public function testCanRenderRowLabelAttributes()
{
$element = new Element('foo');
Expand Down

0 comments on commit 7f524a3

Please sign in to comment.