File indexing completed on 2025-03-02 05:29:19
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Dojo 0017 * @subpackage Form_Element 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 */ 0021 0022 /** Zend_Form_Element */ 0023 // require_once 'Zend/Form/Element.php'; 0024 0025 /** 0026 * Base element for dijit elements 0027 * 0028 * @category Zend 0029 * @package Zend_Dojo 0030 * @subpackage Form_Element 0031 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0032 * @license http://framework.zend.com/license/new-bsd New BSD License 0033 * @version $Id$ 0034 */ 0035 abstract class Zend_Dojo_Form_Element_Dijit extends Zend_Form_Element 0036 { 0037 /** 0038 * Dijit parameters 0039 * @var array 0040 */ 0041 public $dijitParams = array(); 0042 0043 /** 0044 * View helper to use 0045 * @var string 0046 */ 0047 public $helper; 0048 0049 /** 0050 * Constructor 0051 * 0052 * @todo Should we set dojo view helper paths here? 0053 * @param mixed $spec 0054 * @param mixed $options 0055 * @return void 0056 */ 0057 public function __construct($spec, $options = null) 0058 { 0059 $this->addPrefixPath('Zend_Dojo_Form_Decorator', 'Zend/Dojo/Form/Decorator', 'decorator'); 0060 parent::__construct($spec, $options); 0061 } 0062 0063 /** 0064 * Set a dijit parameter 0065 * 0066 * @param string $key 0067 * @param mixed $value 0068 * @return Zend_Dojo_Form_Element_Dijit 0069 */ 0070 public function setDijitParam($key, $value) 0071 { 0072 $key = (string) $key; 0073 $this->dijitParams[$key] = $value; 0074 return $this; 0075 } 0076 0077 /** 0078 * Set multiple dijit params at once 0079 * 0080 * @param array $params 0081 * @return Zend_Dojo_Form_Element_Dijit 0082 */ 0083 public function setDijitParams(array $params) 0084 { 0085 $this->dijitParams = array_merge($this->dijitParams, $params); 0086 return $this; 0087 } 0088 0089 /** 0090 * Does the given dijit parameter exist? 0091 * 0092 * @param string $key 0093 * @return bool 0094 */ 0095 public function hasDijitParam($key) 0096 { 0097 return array_key_exists($key, $this->dijitParams); 0098 } 0099 0100 /** 0101 * Get a single dijit parameter 0102 * 0103 * @param string $key 0104 * @return mixed 0105 */ 0106 public function getDijitParam($key) 0107 { 0108 $key = (string) $key; 0109 if ($this->hasDijitParam($key)) { 0110 return $this->dijitParams[$key]; 0111 } 0112 return null; 0113 } 0114 0115 /** 0116 * Retrieve all dijit parameters 0117 * 0118 * @return array 0119 */ 0120 public function getDijitParams() 0121 { 0122 return $this->dijitParams; 0123 } 0124 0125 /** 0126 * Remove a single dijit parameter 0127 * 0128 * @param string $key 0129 * @return Zend_Dojo_Form_Element_Dijit 0130 */ 0131 public function removeDijitParam($key) 0132 { 0133 $key = (string) $key; 0134 if (array_key_exists($key, $this->dijitParams)) { 0135 unset($this->dijitParams[$key]); 0136 } 0137 return $this; 0138 } 0139 0140 /** 0141 * Clear all dijit parameters 0142 * 0143 * @return Zend_Dojo_Form_Element_Dijit 0144 */ 0145 public function clearDijitParams() 0146 { 0147 $this->dijitParams = array(); 0148 return $this; 0149 } 0150 0151 /** 0152 * Load default decorators 0153 * 0154 * @return void 0155 */ 0156 public function loadDefaultDecorators() 0157 { 0158 if ($this->loadDefaultDecoratorsIsDisabled()) { 0159 return; 0160 } 0161 0162 $decorators = $this->getDecorators(); 0163 if (empty($decorators)) { 0164 $this->addDecorator('DijitElement') 0165 ->addDecorator('Errors') 0166 ->addDecorator('Description', array('tag' => 'p', 'class' => 'description')) 0167 ->addDecorator('HtmlTag', array('tag' => 'dd')) 0168 ->addDecorator('Label', array('tag' => 'dt')); 0169 } 0170 } 0171 0172 /** 0173 * Set the view object 0174 * 0175 * Ensures that the view object has the dojo view helper path set. 0176 * 0177 * @param Zend_View_Interface $view 0178 * @return Zend_Dojo_Form_Element_Dijit 0179 */ 0180 public function setView(Zend_View_Interface $view = null) 0181 { 0182 if (null !== $view) { 0183 if (false === $view->getPluginLoader('helper')->getPaths('Zend_Dojo_View_Helper')) { 0184 $view->addHelperPath('Zend/Dojo/View/Helper', 'Zend_Dojo_View_Helper'); 0185 } 0186 } 0187 return parent::setView($view); 0188 } 0189 }