|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Dojo |
|
17 * @subpackage Form_Element |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 */ |
|
21 |
|
22 /** Zend_Form_Element */ |
|
23 require_once 'Zend/Form/Element.php'; |
|
24 |
|
25 /** |
|
26 * Base element for dijit elements |
|
27 * |
|
28 * @category Zend |
|
29 * @package Zend_Dojo |
|
30 * @subpackage Form_Element |
|
31 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
32 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
33 * @version $Id: Dijit.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
34 */ |
|
35 abstract class Zend_Dojo_Form_Element_Dijit extends Zend_Form_Element |
|
36 { |
|
37 /** |
|
38 * Dijit parameters |
|
39 * @var array |
|
40 */ |
|
41 public $dijitParams = array(); |
|
42 |
|
43 /** |
|
44 * View helper to use |
|
45 * @var string |
|
46 */ |
|
47 public $helper; |
|
48 |
|
49 /** |
|
50 * Constructor |
|
51 * |
|
52 * @todo Should we set dojo view helper paths here? |
|
53 * @param mixed $spec |
|
54 * @param mixed $options |
|
55 * @return void |
|
56 */ |
|
57 public function __construct($spec, $options = null) |
|
58 { |
|
59 $this->addPrefixPath('Zend_Dojo_Form_Decorator', 'Zend/Dojo/Form/Decorator', 'decorator'); |
|
60 parent::__construct($spec, $options); |
|
61 } |
|
62 |
|
63 /** |
|
64 * Set a dijit parameter |
|
65 * |
|
66 * @param string $key |
|
67 * @param mixed $value |
|
68 * @return Zend_Dojo_Form_Element_Dijit |
|
69 */ |
|
70 public function setDijitParam($key, $value) |
|
71 { |
|
72 $key = (string) $key; |
|
73 $this->dijitParams[$key] = $value; |
|
74 return $this; |
|
75 } |
|
76 |
|
77 /** |
|
78 * Set multiple dijit params at once |
|
79 * |
|
80 * @param array $params |
|
81 * @return Zend_Dojo_Form_Element_Dijit |
|
82 */ |
|
83 public function setDijitParams(array $params) |
|
84 { |
|
85 $this->dijitParams = array_merge($this->dijitParams, $params); |
|
86 return $this; |
|
87 } |
|
88 |
|
89 /** |
|
90 * Does the given dijit parameter exist? |
|
91 * |
|
92 * @param string $key |
|
93 * @return bool |
|
94 */ |
|
95 public function hasDijitParam($key) |
|
96 { |
|
97 return array_key_exists($key, $this->dijitParams); |
|
98 } |
|
99 |
|
100 /** |
|
101 * Get a single dijit parameter |
|
102 * |
|
103 * @param string $key |
|
104 * @return mixed |
|
105 */ |
|
106 public function getDijitParam($key) |
|
107 { |
|
108 $key = (string) $key; |
|
109 if ($this->hasDijitParam($key)) { |
|
110 return $this->dijitParams[$key]; |
|
111 } |
|
112 return null; |
|
113 } |
|
114 |
|
115 /** |
|
116 * Retrieve all dijit parameters |
|
117 * |
|
118 * @return array |
|
119 */ |
|
120 public function getDijitParams() |
|
121 { |
|
122 return $this->dijitParams; |
|
123 } |
|
124 |
|
125 /** |
|
126 * Remove a single dijit parameter |
|
127 * |
|
128 * @param string $key |
|
129 * @return Zend_Dojo_Form_Element_Dijit |
|
130 */ |
|
131 public function removeDijitParam($key) |
|
132 { |
|
133 $key = (string) $key; |
|
134 if (array_key_exists($key, $this->dijitParams)) { |
|
135 unset($this->dijitParams[$key]); |
|
136 } |
|
137 return $this; |
|
138 } |
|
139 |
|
140 /** |
|
141 * Clear all dijit parameters |
|
142 * |
|
143 * @return Zend_Dojo_Form_Element_Dijit |
|
144 */ |
|
145 public function clearDijitParams() |
|
146 { |
|
147 $this->dijitParams = array(); |
|
148 return $this; |
|
149 } |
|
150 |
|
151 /** |
|
152 * Load default decorators |
|
153 * |
|
154 * @return void |
|
155 */ |
|
156 public function loadDefaultDecorators() |
|
157 { |
|
158 if ($this->loadDefaultDecoratorsIsDisabled()) { |
|
159 return; |
|
160 } |
|
161 |
|
162 $decorators = $this->getDecorators(); |
|
163 if (empty($decorators)) { |
|
164 $this->addDecorator('DijitElement') |
|
165 ->addDecorator('Errors') |
|
166 ->addDecorator('Description', array('tag' => 'p', 'class' => 'description')) |
|
167 ->addDecorator('HtmlTag', array('tag' => 'dd')) |
|
168 ->addDecorator('Label', array('tag' => 'dt')); |
|
169 } |
|
170 } |
|
171 |
|
172 /** |
|
173 * Set the view object |
|
174 * |
|
175 * Ensures that the view object has the dojo view helper path set. |
|
176 * |
|
177 * @param Zend_View_Interface $view |
|
178 * @return Zend_Dojo_Form_Element_Dijit |
|
179 */ |
|
180 public function setView(Zend_View_Interface $view = null) |
|
181 { |
|
182 if (null !== $view) { |
|
183 if (false === $view->getPluginLoader('helper')->getPaths('Zend_Dojo_View_Helper')) { |
|
184 $view->addHelperPath('Zend/Dojo/View/Helper', 'Zend_Dojo_View_Helper'); |
|
185 } |
|
186 } |
|
187 return parent::setView($view); |
|
188 } |
|
189 } |