Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 halkyon authored
Showing with 17 additions and 34 deletions.
  1. +16 −14 forms/CompositeField.php
  2. +1 −20 forms/SelectionGroup.php
30 forms/CompositeField.php
View
@@ -298,39 +298,42 @@ function rootFieldSet() {
}
/**
- * Return a readonly version of this field. Keeps the composition but returns readonly
- * versions of all the children
+ * Return a readonly version of this field. Keeps the composition but returns readonly
+ * versions of all the child {@link FormField} objects.
+ *
+ * @return CompositeField
*/
public function performReadonlyTransformation() {
$newChildren = new FieldList();
$clone = clone $this;
- foreach($clone->getChildren() as $idx => $child) {
+ if($clone->getChildren()) foreach($clone->getChildren() as $idx => $child) {
if(is_object($child)) $child = $child->transform(new ReadonlyTransformation());
$newChildren->push($child, $idx);
}
$clone->children = $newChildren;
$clone->readonly = true;
+
return $clone;
}
/**
- * Return a readonly version of this field. Keeps the composition but returns readonly
- * versions of all the children
+ * Return a disabled version of this field. Keeps the composition but returns disabled
+ * versions of all the child {@link FormField} objects.
+ *
+ * @return CompositeField
*/
- public function performDisabledTransformation($trans) {
+ public function performDisabledTransformation() {
$newChildren = new FieldList();
$clone = clone $this;
if($clone->getChildren()) foreach($clone->getChildren() as $idx => $child) {
- if(is_object($child)) {
- $child = $child->transform($trans);
- }
+ if(is_object($child)) $child = $child->transform(new DisabledTransformation());
$newChildren->push($child, $idx);
}
$clone->children = $newChildren;
$clone->readonly = true;
-
+
return $clone;
}
@@ -394,15 +397,14 @@ function debug() {
$result .= "</ul>";
return $result;
}
-
- function validate($validator){
-
+
+ function validate($validator) {
$valid = true;
foreach($this->children as $idx => $child){
$valid = ($child && $child->validate($validator) && $valid);
}
-
return $valid;
}
+
}
21 forms/SelectionGroup.php
View
@@ -27,25 +27,6 @@ function __construct($name, $items) {
Requirements::css(SAPPHIRE_DIR . '/css/SelectionGroup.css');
}
-
- /**
- * Return a readonly version of this field. Keeps the composition but returns readonly
- * versions of all the children
- */
- public function performDisabledTransformation($trans) {
- $newChildren = array();
- $clone = clone $this;
- if($clone->children) foreach($clone->getChildren() as $idx => $child) {
- if(is_object($child)) {
- $child = $child->transform($trans);
- }
- $newChildren[$idx] = $child;
- }
-
- $clone->setChildren(new FieldList($newChildren));
- $clone->setReadonly(true);
- return $clone;
- }
function FieldSet() {
return $this->FieldList();
@@ -76,7 +57,7 @@ function FieldList() {
if(is_object($item)) $newItems[] = $item->customise($extra);
else $newItems[] = new ArrayData($extra);
- $firstSelected = $checked ="";
+ $firstSelected = $checked ="";
}
return new ArrayList($newItems);
}
Please sign in to comment.
Something went wrong with that request. Please try again.