فهرست منبع

ZF-7054: Custom Id in Decorator Fieldset

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@21966 44c647ce-9c0f-0410-b52a-842ac1e357ba
alab 15 سال پیش
والد
کامیت
7af12c561f
2فایلهای تغییر یافته به همراه19 افزوده شده و 5 حذف شده
  1. 5 5
      library/Zend/Form/Decorator/Fieldset.php
  2. 14 0
      tests/Zend/Form/Decorator/FieldsetTest.php

+ 5 - 5
library/Zend/Form/Decorator/Fieldset.php

@@ -126,12 +126,12 @@ class Zend_Form_Decorator_Fieldset extends Zend_Form_Decorator_Abstract
             return $content;
         }
 
-        $legend        = $this->getLegend();
-        $attribs       = $this->getOptions();
-        $name          = $element->getFullyQualifiedName();
+        $legend  = $this->getLegend();
+        $attribs = $this->getOptions();
+        $name    = $element->getFullyQualifiedName();
+        $id      = (string)$element->getId();
 
-        $id = $element->getId();
-        if (!empty($id)) {
+        if (!array_key_exists('id', $attribs) && '' !== $id) {
             $attribs['id'] = 'fieldset-' . $id;
         }
 

+ 14 - 0
tests/Zend/Form/Decorator/FieldsetTest.php

@@ -132,6 +132,20 @@ class Zend_Form_Decorator_FieldsetTest extends PHPUnit_Framework_TestCase
     }
 
     /**
+     * @see ZF-7054
+     */
+    public function testCustomIdSupersedesElementId()
+    {
+        $form = new Zend_Form_SubForm();
+        $form->setName('bar')
+             ->setView($this->getView());
+        $html = $this->decorator->setElement($form)
+                                ->setOption('id', 'foo-id')
+                                ->render('content');
+        $this->assertContains('foo-id', $html);
+    }
+
+    /**
      * @see ZF-2981
      */
     public function testActionAndMethodAttributesShouldNotBePresentInFieldsetTag()