From d64297e9ee1fc4c4d0256cbd238947ba06c91e19 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Wed, 17 Dec 2008 04:20:52 +0000 Subject: [PATCH] Simplified implementation of FieldSet::makeReadonlyField() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@69349 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/FieldSet.php | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/forms/FieldSet.php b/forms/FieldSet.php index 227e20949..e09c6e6c7 100755 --- a/forms/FieldSet.php +++ b/forms/FieldSet.php @@ -471,26 +471,8 @@ class FieldSet extends DataObjectSet { * @param string|FormField */ function makeFieldReadonly($field) { - $fieldName = ($field instanceof FormField) ? $field->Name() : $field; - - // Iterate on items, looking for the applicable field - foreach($this->items as $i => $item) { - if($item->isComposite()) { - $item->makeFieldReadonly($fieldName); - } else { - // Once it's found, use FormField::transform to turn the field into a readonly version of itself. - if($item->Name() == $fieldName) { - $this->items[$i] = $item->transform(new ReadonlyTransformation()); - - // Clear an internal cache - $this->sequentialSet = null; - - // A true results indicates that the field was foudn - return true; - } - } - } - return false; + $srcField = $this->dataFieldByName($fieldName); + $this->replaceField($fieldName, $srcField->performReadonlyTransformation()); } /** @@ -552,4 +534,4 @@ class FieldSet extends DataObjectSet { } -?> \ No newline at end of file +?>