1792 Posts in 588 Topics by 560 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 485 Views |
-
gridField getCMSactions and summaryfields

10 July 2012 at 12:16am Last edited: 10 July 2012 12:20am
Hi,
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
{
$datepicker->setValue(date('d.m.Y'));
}
$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
-
Re: gridField getCMSactions and summaryfields

20 October 2012 at 12:03pm
regarding the 2nd question, it should be
return $this->dbObject('date')->Nice();
-
Re: gridField getCMSactions and summaryfields

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() {
parent::populateDefaults();
$this->SomeDate = date('Y-m-d');
}
| 485 Views | ||
|
Page:
1
|
Go to Top |


