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.
This commit is contained in:
Sean Harvey 2012-04-12 12:24:06 +12:00
parent 852ffcf492
commit 2b8e14fdff
2 changed files with 17 additions and 34 deletions

View File

@ -299,32 +299,35 @@ class CompositeField extends FormField {
/** /**
* Return a readonly version of this field. Keeps the composition but returns readonly * Return a readonly version of this field. Keeps the composition but returns readonly
* versions of all the children * versions of all the child {@link FormField} objects.
*
* @return CompositeField
*/ */
public function performReadonlyTransformation() { public function performReadonlyTransformation() {
$newChildren = new FieldList(); $newChildren = new FieldList();
$clone = clone $this; $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()); if(is_object($child)) $child = $child->transform(new ReadonlyTransformation());
$newChildren->push($child, $idx); $newChildren->push($child, $idx);
} }
$clone->children = $newChildren; $clone->children = $newChildren;
$clone->readonly = true; $clone->readonly = true;
return $clone; return $clone;
} }
/** /**
* Return a readonly version of this field. Keeps the composition but returns readonly * Return a disabled version of this field. Keeps the composition but returns disabled
* versions of all the children * versions of all the child {@link FormField} objects.
*
* @return CompositeField
*/ */
public function performDisabledTransformation($trans) { public function performDisabledTransformation() {
$newChildren = new FieldList(); $newChildren = new FieldList();
$clone = clone $this; $clone = clone $this;
if($clone->getChildren()) foreach($clone->getChildren() as $idx => $child) { if($clone->getChildren()) foreach($clone->getChildren() as $idx => $child) {
if(is_object($child)) { if(is_object($child)) $child = $child->transform(new DisabledTransformation());
$child = $child->transform($trans);
}
$newChildren->push($child, $idx); $newChildren->push($child, $idx);
} }
@ -396,13 +399,12 @@ class CompositeField extends FormField {
} }
function validate($validator) { function validate($validator) {
$valid = true; $valid = true;
foreach($this->children as $idx => $child){ foreach($this->children as $idx => $child){
$valid = ($child && $child->validate($validator) && $valid); $valid = ($child && $child->validate($validator) && $valid);
} }
return $valid; return $valid;
} }
} }

View File

@ -28,25 +28,6 @@ class SelectionGroup extends CompositeField {
Requirements::css(SAPPHIRE_DIR . '/css/SelectionGroup.css'); 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() { function FieldSet() {
return $this->FieldList(); return $this->FieldList();
} }