ZF-6871: Zend_Form_Decorator_Label: Unable to manually define ID, setID/setOption('id') does nothing

Issue Type: Sub-task Created: 2009-06-01T02:45:16.000+0000 Last Updated: 2010-04-21T12:57:21.000+0000 Status: Resolved Fix version(s): - 1.11.0 (02/Nov/10)

Reporter: Eugene Song (bakadesu) Assignee: Christian Albrecht (alab) Tags: - Zend_Form

Related issues: Attachments:


Current Zend_Form_Decorator_Label does not allow to manually define ID to the label, as it currently sets the ID to elements name with a "-label" suffix.

<pre class="highlight">
$decorator = $element->getDecorator('Label');
$decorator->setId('testLabelWhateverID');            // Does nothing
$decorator->setOption('id', 'testLabelWhateverID');  // Does nothing

The following modification would allow the override of the ID when specified and still retain auto generation of the ID from the element name.

<pre class="highlight">
    public function render($content)
        $element = $this->getElement();
        $view    = $element->getView();
        if (null === $view) {
            return $content;

        $label     = $this->getLabel();
        $separator = $this->getSeparator();
        $placement = $this->getPlacement();
        $tag       = $this->getTag();
//      $id        = $this->getId();
        $id        = $this->getId() ? $this->getId() : $element->getName() . '-label';
        $class     = $this->getClass();
        $options   = $this->getOptions();

        if (empty($label) && empty($tag)) {
            return $content;

        if (!empty($label)) {
            $options['class'] = $class;
            $label = $view->formLabel($element->getFullyQualifiedName(), trim($label), $options);
        } else {
            $label = ' ';

        if (null !== $tag) {
            require_once 'Zend/Form/Decorator/HtmlTag.php';
            $decorator = new Zend_Form_Decorator_HtmlTag();
//          $decorator->setOptions(array('tag' => $tag,
//                                       'id'  => $this->getElement()->getName() . '-label'));
            $decorator->setOptions(array('tag' => $tag,
                                         'id'  => $id));

            $label = $decorator->render($label);

        switch ($placement) {
            case self::APPEND:
                return $content . $separator . $label;
            case self::PREPEND:
                return $label . $separator . $content;


Posted by Eugene Song (bakadesu) on 2009-07-12T15:17:38.000+0000

Easier to just use custom decorators. Although would be nice to have in the documentation that certain options/attributes don't work in various form decorators.

Posted by Christian Albrecht (alab) on 2010-04-21T11:27:07.000+0000

Fixed in trunk r21961 and 1.10 release branch.

Posted by Christian Albrecht (alab) on 2010-04-21T12:22:21.000+0000

Reverted release-1.10 merge r21962, and sheduling for next minor release.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.