Browse Source

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@21964 44c647ce-9c0f-0410-b52a-842ac1e357ba

alab 16 years ago
parent
commit
6dbbfff717

+ 5 - 1
library/Zend/Form/Decorator/HtmlTag.php

@@ -84,7 +84,11 @@ class Zend_Form_Decorator_HtmlTag extends Zend_Form_Decorator_Abstract
         foreach ((array) $attribs as $key => $val) {
             $key = htmlspecialchars($key, ENT_COMPAT, $enc);
             if (is_array($val)) {
-                $val = implode(' ', $val);
+                if (array_key_exists('callback', $val)) {
+                    $val = $val['callback']($this);
+                } else {
+                    $val = implode(' ', $val);
+                }
             }
             $val    = htmlspecialchars($val, ENT_COMPAT, $enc);
             $xhtml .= " $key=\"$val\"";

+ 8 - 5
library/Zend/Form/Element.php

@@ -315,12 +315,15 @@ class Zend_Form_Element implements Zend_Validate_Interface
 
         $decorators = $this->getDecorators();
         if (empty($decorators)) {
+            $getId = create_function('$decorator',
+                                     'return $decorator->getElement()->getId()
+                                             . "-element";');
             $this->addDecorator('ViewHelper')
-                ->addDecorator('Errors')
-                ->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
-                ->addDecorator('HtmlTag', array('tag' => 'dd',
-                                                'id'  => $this->getName() . '-element'))
-                ->addDecorator('Label', array('tag' => 'dt'));
+                 ->addDecorator('Errors')
+                 ->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
+                 ->addDecorator('HtmlTag', array('tag' => 'dd',
+                                                 'id'  => array('callback' => $getId)))
+                 ->addDecorator('Label', array('tag' => 'dt'));
         }
     }
 

+ 12 - 0
tests/Zend/Form/FormTest.php

@@ -1112,6 +1112,18 @@ class Zend_Form_FormTest extends PHPUnit_Framework_TestCase
         $this->assertFalse($this->form->isArray());
     }
 
+    /** @issue ZF-6741 */
+    public function testUseIdForDdTagByDefault()
+    {
+        $this->form->addElement('text', 'foo')
+                   ->addSubForm(new Zend_Form_SubForm(), 'bar')
+                   ->bar->addElement('text', 'foo');
+
+        $html = $this->form->setView($this->getView())->render();
+        var_dump($html);
+        $this->assertRegexp('/<dd.*?bar-foo.*?>/', $html);
+    }
+
     /**
      * @group ZF-3146
      */