mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
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
This commit is contained in:
parent
3d4d4d0c42
commit
fce3767389
@ -240,12 +240,27 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user