mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX Versioned_Version->relField() so fields can be used in GridField etc
Copied from DataObject, since we can't use the $fallback opion in this case (will try to retrieve from wrong class)
This commit is contained in:
parent
703c10aa0e
commit
f7cd316d1f
@ -1210,4 +1210,32 @@ class Versioned_Version extends ViewableData {
|
||||
public function Published() {
|
||||
return !empty( $this->record['WasPublished'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Copied from DataObject to allow access via dot notation.
|
||||
*/
|
||||
public function relField($fieldName) {
|
||||
$component = $this;
|
||||
|
||||
if(strpos($fieldName, '.') !== false) {
|
||||
$parts = explode('.', $fieldName);
|
||||
$fieldName = array_pop($parts);
|
||||
|
||||
// Traverse dot syntax
|
||||
foreach($parts as $relation) {
|
||||
if($component instanceof SS_List) {
|
||||
if(method_exists($component,$relation)) $component = $component->$relation();
|
||||
else $component = $component->relation($relation);
|
||||
} else {
|
||||
$component = $component->$relation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Unlike has-one's, these "relations" can return false
|
||||
if($component) {
|
||||
if ($component->hasMethod($fieldName)) return $component->$fieldName();
|
||||
return $component->$fieldName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user