13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_View |
16 * @package Zend_View |
17 * @subpackage Helper |
17 * @subpackage Helper |
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @version $Id: FormElement.php 22290 2010-05-25 14:27:12Z matthew $ |
20 * @version $Id: FormElement.php 24823 2012-05-29 19:52:12Z rob $ |
21 */ |
21 */ |
22 |
22 |
23 /** |
23 /** |
24 * @see Zend_View_Helper_HtmlElement |
24 * @see Zend_View_Helper_HtmlElement |
25 */ |
25 */ |
29 * Base helper for form elements. Extend this, don't use it on its own. |
29 * Base helper for form elements. Extend this, don't use it on its own. |
30 * |
30 * |
31 * @category Zend |
31 * @category Zend |
32 * @package Zend_View |
32 * @package Zend_View |
33 * @subpackage Helper |
33 * @subpackage Helper |
34 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
34 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
35 * @license http://framework.zend.com/license/new-bsd New BSD License |
35 * @license http://framework.zend.com/license/new-bsd New BSD License |
36 */ |
36 */ |
37 abstract class Zend_View_Helper_FormElement extends Zend_View_Helper_HtmlElement |
37 abstract class Zend_View_Helper_FormElement extends Zend_View_Helper_HtmlElement |
38 { |
38 { |
39 /** |
39 /** |
40 * @var Zend_Translate |
40 * @var Zend_Translate_Adapter|null |
41 */ |
41 */ |
42 protected $_translator; |
42 protected $_translator; |
43 |
43 |
44 /** |
44 /** |
45 * Get translator |
45 * Get translator |
46 * |
46 * |
47 * @return Zend_Translate |
47 * @return Zend_Translate_Adapter|null |
48 */ |
48 */ |
49 public function getTranslator() |
49 public function getTranslator() |
50 { |
50 { |
51 return $this->_translator; |
51 return $this->_translator; |
52 } |
52 } |
53 |
53 |
54 /** |
54 /** |
55 * Set translator |
55 * Set translator |
56 * |
56 * |
57 * @param $translator|null Zend_Translate |
57 * @param Zend_Translate|Zend_Translate_Adapter|null $translator |
58 * @return Zend_View_Helper_FormElement |
58 * @return Zend_View_Helper_FormElement |
59 */ |
59 */ |
60 public function setTranslator($translator = null) |
60 public function setTranslator($translator = null) |
61 { |
61 { |
62 if (null === $translator) { |
62 if (null === $translator) { |
113 if (isset($name[$key])) { |
113 if (isset($name[$key])) { |
114 $info[$key] = $name[$key]; |
114 $info[$key] = $name[$key]; |
115 } |
115 } |
116 } |
116 } |
117 |
117 |
118 // If all helper options are passed as an array, attribs may have |
118 // If all helper options are passed as an array, attribs may have |
119 // been as well |
119 // been as well |
120 if (null === $attribs) { |
120 if (null === $attribs) { |
121 $attribs = $info['attribs']; |
121 $attribs = $info['attribs']; |
122 } |
122 } |
123 } |
123 } |
144 $info['id'] = (string)$attribs['id']; |
144 $info['id'] = (string)$attribs['id']; |
145 } else if ('' !== $info['name']) { |
145 } else if ('' !== $info['name']) { |
146 $info['id'] = trim(strtr($info['name'], |
146 $info['id'] = trim(strtr($info['name'], |
147 array('[' => '-', ']' => '')), '-'); |
147 array('[' => '-', ']' => '')), '-'); |
148 } |
148 } |
|
149 |
|
150 // Remove NULL name attribute override |
|
151 if (array_key_exists('name', $attribs) && is_null($attribs['name'])) { |
|
152 unset($attribs['name']); |
|
153 } |
|
154 |
|
155 // Override name in info if specified in attribs |
|
156 if (array_key_exists('name', $attribs) && $attribs['name'] != $info['name']) { |
|
157 $info['name'] = $attribs['name']; |
|
158 } |
149 |
159 |
150 // Determine escaping from attributes |
160 // Determine escaping from attributes |
151 if (array_key_exists('escape', $attribs)) { |
161 if (array_key_exists('escape', $attribs)) { |
152 $info['escape'] = (bool)$attribs['escape']; |
162 $info['escape'] = (bool)$attribs['escape']; |
153 } |
163 } |
176 * We have this as a common method because other elements often |
186 * We have this as a common method because other elements often |
177 * need hidden elements for their operation. |
187 * need hidden elements for their operation. |
178 * |
188 * |
179 * @access protected |
189 * @access protected |
180 * |
190 * |
181 * @param $name The element name. |
191 * @param string $name The element name. |
182 * |
192 * @param string $value The element value. |
183 * @param $value The element value. |
193 * @param array $attribs Attributes for the element. |
184 * |
|
185 * @param $attribs Attributes for the element. |
|
186 * |
194 * |
187 * @return string A hidden element. |
195 * @return string A hidden element. |
188 */ |
196 */ |
189 protected function _hidden($name, $value = null, $attribs = null) |
197 protected function _hidden($name, $value = null, $attribs = null) |
190 { |
198 { |