Details
Description
Description:
The tag "option" does not appear to be cleared properly when setTag is used and is rendered as an html property.
PHP
$start_date = new Zend_Form_Element_Text('start_date', array('label' => 'Start Date'));
$start_date->getDecorator('label')->setTag('div');
$form->addElement($start_date);
Produces:
HTML
<div><label for="start_date" tag="dt" class="optional">Start Date</label></div>
Diff of quick fix
Index: Form/Decorator/Label.php
===================================================================
--- Form/Decorator/Label.php (revision 12325)
+++ Form/Decorator/Label.php (working copy)
@@ -289,6 +289,10 @@
}
if (!empty($label)) {
+ if (!empty($tag) && isset($options['tag'])) {
+ unset($options['tag']);
+ }
+
$options['class'] = $class;
$label = $view->formLabel($element->getFullyQualifiedName(), trim($label), $options);
} else {
I encounter this problem as well, and not only with the Label decorator. Setting a tag on an HtmlTag decorator instance will render some invalid HTML code, with the tag attribute being rendered.
This doesn't happen when no tag is defined (the default one is used instead) because the getTag() method of the decorator (called in the render() method) will try to get this attribute from the options, set it in the object property with the setTag() method, and then explicitly remove the "tag" attribute from the options using removeOption().
The patch I made is slightly different to yours, as the setTag() method now sets the provided tag in the options instead of the class property, and then it will be the getTag() option which will do the same job as it did. I did that to ensure that the default "dt" tag option is never used between the time the object is instantiated and the time it is rendered.
Index: Form/Decorator/Label.php =================================================================== --- Form/Decorator/Label.php (revision 13615) +++ Form/Decorator/Label.php (working copy) @@ -101,7 +101,7 @@ if (empty($tag)) { $this->_tag = null; } else { - $this->_tag = (string) $tag; + $this->setOption('tag', (string) $tag); } return $this; } @@ -117,7 +117,7 @@ $tag = $this->getOption('tag'); if (null !== $tag) { $this->removeOption('tag'); - $this->setTag($tag); + $this->_tag = $tag; } return $tag; }Index: Form/Decorator/Label.php =================================================================== --- Form/Decorator/Label.php (revision 13615) +++ Form/Decorator/Label.php (working copy) @@ -101,7 +101,7 @@ if (empty($tag)) { $this->_tag = null; } else { - $this->_tag = (string) $tag; + $this->setOption('tag', (string) $tag); } return $this; } @@ -117,7 +117,7 @@ $tag = $this->getOption('tag'); if (null !== $tag) { $this->removeOption('tag'); - $this->setTag($tag); + $this->_tag = $tag; } return $tag; }