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

@ -298,39 +298,42 @@ class CompositeField extends FormField {
}
/**
* 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 @@ class CompositeField extends FormField {
$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;
}
}

View File

@ -27,25 +27,6 @@ class SelectionGroup extends CompositeField {
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 @@ class SelectionGroup extends CompositeField {
if(is_object($item)) $newItems[] = $item->customise($extra);
else $newItems[] = new ArrayData($extra);
$firstSelected = $checked ="";
$firstSelected = $checked ="";
}
return new ArrayList($newItems);
}