Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

DOM doesnt inherit summaryFields() automatically


Reply


4 Posts   1448 Views

Avatar
Pigeon

Community Member, 243 Posts

28 April 2010 at 1:33am

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.

Avatar
UncleCheese

Forum Moderator, 4096 Posts

28 April 2010 at 2:17am

Yup. Nice catch. I added that functionality before I knew that you could cast summaryFields() as a function.

Avatar
Pigeon

Community Member, 243 Posts

28 April 2010 at 2:38am

Edited: 28/04/2010 3:04am

Ah, ok.

It would be nice to see it pushed into the trunk 0:-)

cheers cheesey.

Also, did you see this issue: http://silverstripe.org/dataobjectmanager-module-forum/show/282867?start=0#post282894

Any plans to add set_source_id() to the core?

EDIT:
Actually, i just noticed that DataObject has a method summaryFields(), so my condition will always be true. But, the inbuilt summaryFields looks for the summary_fields static anyway. So it can end there really. [line 3157 of DataObject.php]

it seems like your code is slightly redundant and restrictive as it doesn't facilitate the use of a summaryfields decorator :/

So really I think the best idea would actually to remove that code (line 97 - 108 of DataObjectManager.php), rather than modify it.

Avatar
ciaranhickey

Community Member, 17 Posts

6 August 2010 at 12:37am

Edited: 06/08/2010 12:43am

EDIT: Problem Solved. Please ignore!

Hi,

Apologies for hi-jacking this thread but I'm trying to get Summary Fields working for my DOM. I've tried the above approach using a method to call the static variable summary_fields but my listview is still showing every one of my fields.

I've posted my issue here:
[url]http://ssorg.bigbird.silverstripe.com/dataobjectmanager-module-forum/show/289984?showPost=289984[/url]

Maybe my understanding of summary fields for DOM is incorrect but I've used it with ModelAdmin before to limit what gets displayed in the backend list view (of my objects).

Would appreciate any help or pointers on this.

Thanks a lot,
Ciarán