Changeset 7046
- Timestamp:
- 01/14/08 13:25:22 (10 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/widget/sfWidgetFormSchemaDecorator.class.php
r6220 r7046 26 26 * Constructor. 27 27 * 28 * The decorated widget is cloned.29 *30 28 * @param sfWidgetFormSchema A sfWidgetFormSchema instance 31 29 * @param string A decorator string … … 35 33 public function __construct(sfWidgetFormSchema $widget, $decorator) 36 34 { 37 $this->widget = clone$widget;35 $this->widget = $widget; 38 36 $this->decorator = $decorator; 39 37 40 $this->nameFormat = $widget->getNameFormat(); 41 $this->formFormatters = $widget->getFormFormatters(); 42 $this->formFormatter = $widget->getFormFormatterName(); 43 44 $this->attributes = $widget->getAttributes(); 45 $this->options = $widget->getOptions(); 46 $this->labels = $widget->getLabels(); 47 $this->helps = $widget->getHelps(); 38 parent::__construct(); 39 } 40 41 /** 42 * Returns the decorated widget. 43 * 44 * @param sfWidget The decorated widget 45 */ 46 public function getWidget() 47 { 48 return $this->widget; 48 49 } 49 50 … … 53 54 public function render($name, $values = array(), $attributes = array(), $errors = array()) 54 55 { 55 $this->widget->setNameFormat($this->nameFormat);56 foreach ($this->formFormatters as $name => $formFormatter)57 {58 $this->widget->addFormFormatter($name, $formFormatter);59 }60 $this->widget->setFormFormatterName($this->formFormatter);61 62 $this->widget->setAttributes($this->attributes);63 $this->widget->setOptions($this->options);64 $this->widget->setLabels($this->labels);65 $this->widget->setHelps($this->helps);66 67 56 return strtr($this->decorator, array('%content%' => $this->widget->render($name, $values, $attributes, $errors))); 68 57 } … … 71 60 * @see sfWidgetFormSchema 72 61 */ 62 public function addFormFormatter($name, sfWidgetFormSchemaFormatter $formatter) 63 { 64 return $this->widget->addFormFormatter($name, $formatter); 65 } 66 67 /** 68 * @see sfWidgetFormSchema 69 */ 70 public function getFormFormatters() 71 { 72 return $this->widget->getFormFormatters(); 73 } 74 75 /** 76 * @see sfWidgetFormSchema 77 */ 78 public function setFormFormatterName($name) 79 { 80 $this->widget->setFormFormatterName($name); 81 } 82 83 /** 84 * @see sfWidgetFormSchema 85 */ 86 public function getFormFormatterName() 87 { 88 return $this->widget->getFormFormatterName(); 89 } 90 91 /** 92 * @see sfWidgetFormSchema 93 */ 94 public function getFormFormatter() 95 { 96 return $this->widget->getFormFormatter(); 97 } 98 99 /** 100 * @see sfWidgetFormSchema 101 */ 102 public function setNameFormat($format) 103 { 104 $this->widget->setNameFormat($format); 105 } 106 107 /** 108 * @see sfWidgetFormSchema 109 */ 110 public function getNameFormat() 111 { 112 return $this->widget->getNameFormat(); 113 } 114 115 /** 116 * @see sfWidgetFormSchema 117 */ 118 public function setLabels($labels) 119 { 120 $this->widget->setLabels($labels); 121 } 122 123 /** 124 * @see sfWidgetFormSchema 125 */ 126 public function getLabels() 127 { 128 return $this->widget->getLabels(); 129 } 130 131 /** 132 * @see sfWidgetFormSchema 133 */ 134 public function setLabel($name, $value) 135 { 136 $this->widget->setLabel($name, $value); 137 } 138 139 /** 140 * @see sfWidgetFormSchema 141 */ 142 public function getLabel($name) 143 { 144 return $this->widget->getLabel($name); 145 } 146 147 /** 148 * @see sfWidgetFormSchema 149 */ 150 public function setHelps($helps) 151 { 152 $this->widget->setHelps($helps); 153 } 154 155 /** 156 * @see sfWidgetFormSchema 157 */ 158 public function getHelps() 159 { 160 return $this->widget->getHelps(); 161 } 162 163 /** 164 * @see sfWidgetFormSchema 165 */ 166 public function setHelp($name, $help) 167 { 168 $this->widget->setHelp($name, $help); 169 } 170 171 /** 172 * @see sfWidgetFormSchema 173 */ 174 public function getHelp($name) 175 { 176 return $this->widget->getHelp($name); 177 } 178 179 /** 180 * @see sfWidgetFormSchema 181 */ 182 public function needsMultipartForm() 183 { 184 return $this->widget->needsMultipartForm(); 185 } 186 187 /** 188 * @see sfWidgetFormSchema 189 */ 190 public function renderField($name, $value = null, $errors = array()) 191 { 192 return $this->widget->renderField($name, $value, $errors); 193 } 194 195 /** 196 * @see sfWidgetFormSchema 197 */ 198 public function generateLabel($name) 199 { 200 return $this->widget->generateLabel($name); 201 } 202 203 /** 204 * @see sfWidgetFormSchema 205 */ 206 public function generateLabelName($name) 207 { 208 return $this->widget->generateLabelName($name); 209 } 210 211 /** 212 * @see sfWidgetFormSchema 213 */ 214 public function generateName($name) 215 { 216 return $this->widget->generateName($name); 217 } 218 219 /** 220 * @see sfWidgetFormSchema 221 */ 222 public function getParent() 223 { 224 return $this->widget->getParent(); 225 } 226 227 /** 228 * @see sfWidgetFormSchema 229 */ 230 public function setParent(sfWidgetFormSchema $parent) 231 { 232 $this->widget->setParent($parent); 233 } 234 235 /** 236 * @see sfWidgetFormSchema 237 */ 238 public function getFields() 239 { 240 return $this->widget->getFields(); 241 } 242 243 /** 244 * @see sfWidgetFormSchema 245 */ 246 public function getPositions() 247 { 248 return $this->widget->getPositions(); 249 } 250 251 /** 252 * @see sfWidgetFormSchema 253 */ 254 public function setPositions($positions) 255 { 256 $this->widget->setPositions($positions); 257 } 258 259 /** 260 * @see sfWidgetFormSchema 261 */ 262 public function moveField($field, $action, $pivot = null) 263 { 264 return $this->widget->moveField($field, $action, $pivot); 265 } 266 267 /** 268 * @see sfWidgetFormSchema 269 */ 73 270 public function offsetExists($name) 74 271 { … … 100 297 } 101 298 102 /** 103 * @see sfWidgetFormSchema 104 */ 105 public function getFields() 106 { 107 return $this->widget->getFields(); 299 public function __clone() 300 { 301 $this->widget = clone $this->widget; 108 302 } 109 303 } branches/1.1/test/unit/widget/sfWidgetFormSchemaDecoratorTest.php
r6197 r7046 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test( 9, new lime_output_color());13 $t = new lime_test(15, new lime_output_color()); 14 14 15 15 $w1 = new sfWidgetFormInput(); … … 18 18 19 19 $w = new sfWidgetFormSchemaDecorator($ws, "<table>\n%content%</table>"); 20 21 // ->getWidget() 22 $t->diag('->getWidget()'); 23 $t->is($w->getWidget(), $ws, '->getWidget() returns the decorated widget'); 20 24 21 25 // ->render() … … 35 39 $w['w2'] = $w2; 36 40 $t->is($w->getFields(), array('w1' => $w1, 'w2' => $w2), 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); 37 $t->is($ws->getFields(), array('w1' => $w1 ), 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');41 $t->is($ws->getFields(), array('w1' => $w1, 'w2' => $w2), 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); 38 42 39 43 try … … 49 53 $w = new sfWidgetFormSchemaDecorator($ws, "<table>\n%content%</table>"); 50 54 $t->is(isset($w['w1']), true, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); 51 $t->is(isset($w['w2']), false, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); 55 $t->is(isset($w['w2']), true, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); 56 $t->is(isset($ws['w1']), true, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); 57 $t->is(isset($ws['w2']), true, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); 52 58 53 59 $w = new sfWidgetFormSchemaDecorator($ws, "<table>\n%content%</table>"); 54 60 $t->is($w['w1'], $w1, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); 55 $t->is($w['w2'], null, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); 61 $t->is($w['w2'], $w2, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); 62 $t->is($ws['w1'], $w1, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); 63 $t->is($ws['w2'], $w2, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); 56 64 57 65 $w = new sfWidgetFormSchemaDecorator($ws, "<table>\n%content%</table>"); 58 66 unset($w['w1']); 59 67 $t->is($w['w1'], null, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields'); 68 $t->is($ws['w1'], null, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');