When using complex table fields in the CMS for DataObjects, we are able to set a function called summaryFields() like so:
class MyDO extends DataObject {
...
function summaryFields() {
return array(
'FieldName' => 'Column Name'
}
}
}
which allows us to call a complex table field like so:
class MyPage extends Page {
...
function getCMSFields() {
...
$fields->addFieldToTab('Root.Content.MyDos', new ComplexTableField($this,'MyDOs','MyDO'));
}
}
Notice i have not had to define the summary fields for the object. What CTF does is assumes I want it to use the summaryFields method on MyDO.
However, when using DOM, it intercepts this assumption and instead looks for a static variable called summary_fields on the class.
This means instead (to make it degradable) we have to do:
class MyDO extends DataObject {
...
static $summary_fields = array(
'FieldName' => 'Column Name'
);
function summaryFields() {
return self::$summary_fields;
}
}
Is there any particular reason this standard behaviour is being hijacked by DOM, rather than sticking to the SS convention? I'm sure that summaryFields() used to work in DOM and recently stopped.
relevant code lines:
DOM Hijack: DataObjectManager.php line 98
Default behavior: TableListField.php line 257
Perhaps this is so DOM can show different fields to the CTF, but surely it should see if the class has the method summaryFields() first?
I propse (in replacement to lines 97 - 108 of DataObjectManager.php):
if($fieldList === null) {
if($fields = $SNG->stat('summary_fields')) {
$fieldList = $fields;
}
elseif (method_exists($SNG,'summaryFields') {
$fields = $SNG->summaryFields();
}
else if($db = $SNG->db()) {
$fieldList = array();
foreach($db as $field => $type) {
if($field != "SortOrder")
$fieldList[$field] = DOMUtil::readable_class($field);
}
}
}
rather than it assuming we dont want to use summaryFields() at all.