mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API DataObject#relField now checks for method on model before property
This commit is contained in:
parent
15e2efb55d
commit
367c49d6b1
@ -2514,13 +2514,14 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
* @param $fieldPath string
|
||||
* @return string
|
||||
*/
|
||||
public function relField($fieldPath) {
|
||||
if(strpos($fieldPath, '.') !== false) {
|
||||
$parts = explode('.', $fieldPath);
|
||||
public function relField($fieldName) {
|
||||
$component = $this;
|
||||
|
||||
if(strpos($fieldName, '.') !== false) {
|
||||
$parts = explode('.', $fieldName);
|
||||
$fieldName = array_pop($parts);
|
||||
|
||||
// Traverse dot syntax
|
||||
$component = $this;
|
||||
foreach($parts as $relation) {
|
||||
if($component instanceof SS_List) {
|
||||
if(method_exists($component,$relation)) $component = $component->$relation();
|
||||
@ -2529,11 +2530,10 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
$component = $component->$relation();
|
||||
}
|
||||
}
|
||||
|
||||
return $component->$fieldName;
|
||||
} else {
|
||||
return $this->$fieldPath;
|
||||
}
|
||||
|
||||
if ($component->hasMethod($fieldName)) return $component->$fieldName();
|
||||
return $component->$fieldName;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user