Hi,
I have extended DataObject and was trying to get it to display nice headers in the CMS Overview. According to the documentation it's supposed to be as simple as specifying an associative array. However if I do it like it's done in the documentation the "nice names" don't show up but instead it will display the actual field names as headers in the CMS.
When I tried to add another column (summary field) from another Object from a has_one relationship and thus used the dot notation mentioned and demonstrated in the documentation it displayed the correct nice name for that column and the correct data, however all the other columns were suddenly empty.
The Code:
class MyObj extends DataObject {
private static $db = array(
'dttm' => 'SS_DateTime',
'name' => 'varchar(255)',
'location' => 'varchar(255)',
);
private static $has_one = array('Page' => 'Page', 'Category' => 'MyCategory');
//private static $summary_fields = array('dttm' => 'Date', 'name' => 'Name', 'location' => 'Where'); // Does display content for all columns but only shows raw field names as column headers instead of the nice name.
//private static $summary_fields = array('dttm' => 'Date', 'name' => 'Name', 'location' => 'Where', 'Category.short' => 'Type'); // According to Documentation this should work. Doesn't display any content but Type, has raw field name correct column headers for all but Type.
//private static $summary_fields = array('dttm.Nice' => 'Date', 'name' => 'Name', 'location' => 'Where', 'Category.short' => 'Type'); // According to documentation this should work. Shows no data but Type and Date, has correct column headers for Date and Type ONLY.
//private static $summary_fields = array('dttm.Nice' => 'Date', 'name.Summary' => 'Name', 'location.Summary' => 'Where', 'Category.short' => 'Type'); // Does display content for Date and Type only, has correct column headers for all columns. No Summary on varchar, so not displaying data is to be expected I guess.
private static $summary_fields = array('dttm.Nice' => 'Date', 'name.getValue' => 'Name', 'location.getValue' => 'Where', 'Category.short' => 'Type'); // Finally displays correct Data and column headers for all columns. Guessing the outcome / trying random functions on varchar worked at last.
}
class MyCategory extends DataObject {
private static $db = array(
'name' => 'varchar(60)',
'short' => 'varchar(4)'
);
private static $has_one = array('Page' => 'Page');
private static $summary_fields = array('name', 'short');
}
So it seems that nice column headers only work when you are using dot notation for the summary fields (which is quite a pain and superfluous). I don't necessarily need or want to display nice dates, not to mention having to call a function for each one adds unnecessary overhead.
All of this leads me to believe that there is a Bug, or at the very least undesirable behavior that should be fixed to match the documentation, which makes sense.
All of this has been done on SilverStripe 3.1.2
Even though unrelated, another thing I noticed is that I had to run /dev/build each time I changed the summary_fields in order to see any changes in the CMS in the first place, which seems weird considering that shouldn't cause any modifications to the database (nor were any indicated on the /dev/build output). It's just PHP Code which as far as I can tell gets executed every time the cms page is loaded so there should be no need to run /dev/build for these kind of changes to take effect.