API DataObject#relField now checks for method on model before property

This commit is contained in:
Hamish Friedlander 2012-07-27 14:44:38 +12:00
parent 15e2efb55d
commit 367c49d6b1

View File

@ -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;
}
/**