2
0
Просмотр исходного кода

ZF-7890: allow specifying a rootNode when creating custom dijits

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18668 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 16 лет назад
Родитель
Сommit
4ebddb19bd

+ 5 - 0
library/Zend/Dojo/View/Helper/CustomDijit.php

@@ -72,6 +72,11 @@ class Zend_Dojo_View_Helper_CustomDijit extends Zend_Dojo_View_Helper_DijitConta
             $this->_module = $this->_defaultDojoType;
         }
 
+        if (array_key_exists('rootNode', $params)) {
+            $this->setRootNode($params['rootNode']);
+            unset($params['rootNode']);
+        }
+
         return $this->_createLayoutContainer($id, $value, $params, $attribs);
     }
 

+ 32 - 2
library/Zend/Dojo/View/Helper/Dijit.php

@@ -64,6 +64,12 @@ abstract class Zend_Dojo_View_Helper_Dijit extends Zend_View_Helper_HtmlElement
     protected $_module;
 
     /**
+     * Root node element type for layout elements
+     * @var string
+     */
+    protected $_rootNode = 'div';
+
+    /**
      * Set view
      *
      * Set view and enable dojo
@@ -79,6 +85,29 @@ abstract class Zend_Dojo_View_Helper_Dijit extends Zend_View_Helper_HtmlElement
         return $this;
     }
 
+
+    /**
+     * Get root node type
+     *
+     * @return string
+     */
+    public function getRootNode()
+    {
+        return $this->_rootNode;
+    }
+
+    /**
+     * Set root node type
+     *
+     * @param  string $value
+     * @return Zend_Dojo_View_Helper_Dijit
+     */
+    public function setRootNode($value)
+    {
+        $this->_rootNode = $value;
+        return $this;
+    }
+
     /**
      * Whether or not to use declarative dijit creation
      *
@@ -124,9 +153,10 @@ abstract class Zend_Dojo_View_Helper_Dijit extends Zend_View_Helper_HtmlElement
         $attribs['id'] = $id;
         $attribs = $this->_prepareDijit($attribs, $params, 'layout', $dijit);
 
-        $html = '<div' . $this->_htmlAttribs($attribs) . '>'
+        $nodeType = $this->getRootNode();
+        $html = '<' . $nodeType . $this->_htmlAttribs($attribs) . '>'
               . $content
-              . "</div>\n";
+              . "</$nodeType>\n";
 
         return $html;
     }

+ 12 - 0
tests/Zend/Dojo/View/Helper/CustomDijitTest.php

@@ -159,6 +159,18 @@ class Zend_Dojo_View_Helper_CustomDijitTest extends PHPUnit_Framework_TestCase
         $this->assertContains(">Captured content started\n<", $content);
         $this->assertContains('dojoType="foo.ContentPane"', $content);
     }
+
+    /**
+     * @group ZF-7890
+     */
+    public function testHelperShouldAllowSpecifyingRootNode()
+    {
+        $content = $this->view->customDijit('foo', 'content', array(
+            'dojoType' => 'custom.Dijit',
+            'rootNode' => 'select',
+        ));
+        $this->assertContains('<select', $content);
+    }
 }
 
 class Zend_Dojo_View_Helper_CustomDijitTest_FooContentPane