Skip to content
This repository
Browse code

API CHANGE Fixing CompositeField/SelectionGroup

performReadonlyTransformation and performDisabledTransformation to be
consistent and conform with parent FormField. $trans argument is no longer allowed, just uses
DisabledTransformation or ReadonlyTransformation instead.
  • Loading branch information...
commit 2b8e14fdffe51e25dc8a2062416150ffc167f709 1 parent 852ffcf
Sean Harvey authored April 12, 2012
30  forms/CompositeField.php
@@ -298,39 +298,42 @@ function rootFieldSet() {
298 298
 	}
299 299
 	
300 300
 	/**
301  
-	 * Return a readonly version of this field.  Keeps the composition but returns readonly
302  
-	 * versions of all the children
  301
+	 * Return a readonly version of this field. Keeps the composition but returns readonly
  302
+	 * versions of all the child {@link FormField} objects.
  303
+	 *
  304
+	 * @return CompositeField
303 305
 	 */
304 306
 	public function performReadonlyTransformation() {
305 307
 		$newChildren = new FieldList();
306 308
 		$clone = clone $this;
307  
-		foreach($clone->getChildren() as $idx => $child) {
  309
+		if($clone->getChildren()) foreach($clone->getChildren() as $idx => $child) {
308 310
 			if(is_object($child)) $child = $child->transform(new ReadonlyTransformation());
309 311
 			$newChildren->push($child, $idx);
310 312
 		}
311 313
 
312 314
 		$clone->children = $newChildren;
313 315
 		$clone->readonly = true;
  316
+
314 317
 		return $clone;
315 318
 	}
316 319
 
317 320
 	/**
318  
-	 * Return a readonly version of this field.  Keeps the composition but returns readonly
319  
-	 * versions of all the children
  321
+	 * Return a disabled version of this field. Keeps the composition but returns disabled
  322
+	 * versions of all the child {@link FormField} objects.
  323
+	 *
  324
+	 * @return CompositeField
320 325
 	 */
321  
-	public function performDisabledTransformation($trans) {
  326
+	public function performDisabledTransformation() {
322 327
 		$newChildren = new FieldList();
323 328
 		$clone = clone $this;
324 329
 		if($clone->getChildren()) foreach($clone->getChildren() as $idx => $child) {
325  
-			if(is_object($child)) {
326  
-				$child = $child->transform($trans);
327  
-			}
  330
+			if(is_object($child)) $child = $child->transform(new DisabledTransformation());
328 331
 			$newChildren->push($child, $idx);
329 332
 		}
330 333
 
331 334
 		$clone->children = $newChildren;
332 335
 		$clone->readonly = true;
333  
-		
  336
+
334 337
 		return $clone;
335 338
 	}
336 339
 
@@ -394,15 +397,14 @@ function debug() {
394 397
 		$result .= "</ul>";
395 398
 		return $result;
396 399
 	}
397  
-	
398  
-	function validate($validator){
399  
-		
  400
+
  401
+	function validate($validator) {
400 402
 		$valid = true;
401 403
 		foreach($this->children as $idx => $child){
402 404
 			$valid = ($child && $child->validate($validator) && $valid);
403 405
 		}
404  
-		
405 406
 		return $valid;
406 407
 	}
  408
+
407 409
 }
408 410
 
21  forms/SelectionGroup.php
@@ -27,25 +27,6 @@ function __construct($name, $items) {
27 27
 		
28 28
 		Requirements::css(SAPPHIRE_DIR . '/css/SelectionGroup.css');
29 29
 	}
30  
-	
31  
-	/**
32  
-	 * Return a readonly version of this field.  Keeps the composition but returns readonly
33  
-	 * versions of all the children
34  
-	 */
35  
-	public function performDisabledTransformation($trans) {
36  
-		$newChildren = array();
37  
-		$clone = clone $this;
38  
-		if($clone->children) foreach($clone->getChildren() as $idx => $child) {
39  
-			if(is_object($child)) {
40  
-				$child = $child->transform($trans);
41  
-			}
42  
-			$newChildren[$idx] = $child;
43  
-		}
44  
-
45  
-		$clone->setChildren(new FieldList($newChildren));
46  
-		$clone->setReadonly(true);
47  
-		return $clone;
48  
-	}
49 30
 
50 31
 	function FieldSet() {
51 32
 		return $this->FieldList();
@@ -76,7 +57,7 @@ function FieldList() {
76 57
 			if(is_object($item)) $newItems[] = $item->customise($extra);
77 58
 			else $newItems[] = new ArrayData($extra);
78 59
 
79  
-			$firstSelected = $checked ="";			
  60
+			$firstSelected = $checked ="";
80 61
 		}
81 62
 		return new ArrayList($newItems);
82 63
 	}

0 notes on commit 2b8e14f

Please sign in to comment.
Something went wrong with that request. Please try again.