7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » DOM doesnt inherit summaryFields() automatically
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1077 Views |
-
DOM doesnt inherit summaryFields() automatically

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 257Perhaps 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. -
Re: DOM doesnt inherit summaryFields() automatically

28 April 2010 at 2:17am
Yup. Nice catch. I added that functionality before I knew that you could cast summaryFields() as a function.
-
Re: DOM doesnt inherit summaryFields() automatically

28 April 2010 at 2:38am Last edited: 28 April 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.
-
Re: DOM doesnt inherit summaryFields() automatically

6 August 2010 at 12:37am Last edited: 6 August 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:
http://ssorg.bigbird.silverstripe.com/dataobjectmanager-module-forum/show/289984?showPost=289984Maybe 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
| 1077 Views | ||
|
Page:
1
|
Go to Top |


