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

Added ability to specify label position as an element label option #6752

Closed
wants to merge 2 commits into from

Conversation

carnage
Copy link
Contributor

@carnage carnage commented Oct 12, 2014

Does exactly what it says on the tin

$this->helper->setLabelPosition('append');
$markup = $this->helper->render($element);
$this->assertContains('<label><span>The value for foo:</span><', $markup);
$this->assertContains('</label>', $markup);
Copy link
Contributor

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);
}

@Ocramius Ocramius added this to the 2.4.0 milestone Dec 24, 2014
@Ocramius Ocramius self-assigned this Dec 24, 2014
weierophinney added a commit that referenced this pull request Feb 23, 2015
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
weierophinney added a commit that referenced this pull request Feb 23, 2015
@@ -213,7 +213,13 @@ public function render(ElementInterface $element)
$labelOpen = $labelClose = $label = '';
}

switch ($this->labelPosition) {
$labelPosition = $this->labelPosition;
Copy link
Member

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.

@weierophinney
Copy link
Member

Merged to develop for release in 2.4.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants