From fce37673898d33ed3a61e29ee9a8b5cd0383704c Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Thu, 9 Oct 2008 00:32:10 +0000 Subject: [PATCH] API CHANGE: Added support for dot syntax to FieldSet::fieldByName() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63922 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/FieldSet.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/forms/FieldSet.php b/forms/FieldSet.php index e47b17f92..5b61e4b18 100755 --- a/forms/FieldSet.php +++ b/forms/FieldSet.php @@ -240,15 +240,30 @@ class FieldSet extends DataObjectSet { /** * Returns a named field. + * You can use dot syntax to get fields from child composite fields * * @todo Implement similiarly to dataFieldByName() to support nested sets - or merge with dataFields() */ public function fieldByName($name) { + if(strpos($name,'.') !== false) list($name, $remainder) = explode('.',$name,2); + else $remainder = null; + foreach($this->items as $child) { - if($name == $child->Name() || $name == $child->id) return $child; + if($name == $child->Name() || $name == $child->id) { + if($remainder) { + if($child->isComposite()) { + return $child->fieldByName($remainder); + } else { + user_error("Trying to get field '$remainder' from non-composite field $child->class.$name", E_USER_WARNING); + return null; + } + } else { + return $child; + } + } } } - + /** * Returns a named field in a sequential set. * Use this if you're using nested FormFields.