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.

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

gridField getCMSactions and summaryfields

Go to End

3 Posts   1301 Views


Community Member, 19 Posts

10 July 2012 at 12:16am

Edited: 10/07/2012 12:20am


I have a problem to get cms action of the form. When I have my dataobject (News) listed, I want to difference between edit and create a new one for set date. I mean, when I want to create a new one I want set in the DateField the current date by default, but not when I want to edit or see an existing new that already was saved with other date.

My code:

"News extend to DataObject"

public function getCMSFields()

$fields = parent::getCMSFields();

foreach($fields->dataFields() as $f)

if (get_class($f) == 'DateField')
$datepicker = new DateField('', $f->getName());
$datepicker->setConfig('showcalendar', true);
$datepicker->setConfig('dateformat', 'dd.MM.YYYY');
if($className == 'dNew' && $actionName == 'new') HERE>>> I difference between edit or create
$fields->replaceField($f->getName(), $datepicker);


I have tried with some ways like getCMSActions, getActionName, getURLParameters and I have looked in the core where I think I can have some hints, but nothing.

The other problem I have is in summary fileds. I want to display dates with german format (d.m.y). The function is call but them I don´t know how to get the value for the List. I get empty cells.

public static $summary_fields = array(
'Title' => 'Titel News',
'getDate' => 'Datum',
'teaser' => 'Teaser'

public function getDate()
$date = $this->getField('date');
return $date.Nice ;

Thanks in advance, regards


Community Member, 97 Posts

20 October 2012 at 12:03pm

regarding the 2nd question, it should be

 return $this->dbObject('date')->Nice();


Forum Moderator, 1391 Posts

23 October 2012 at 11:35pm

For setting default values take a look at the populateDefaults() function. This will not work for existing DataObjects with an empty date, but it will set default values for new ones. In your DataObject class:

static $db = array(
	'SomeDate' => 'Date'

public function populateDefaults() {
	$this->SomeDate = date('Y-m-d');