Jump to:

1971 Posts in 1275 Topics by 607 members

Form Questions

SilverStripe Forums » Form Questions » gridField getCMSactions and summaryfields

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

Page: 1
Go to End
Author Topic: 728 Views
  • Bolixe
    Avatar
    Community Member
    17 Posts

    gridField getCMSactions and summaryfields Link to this post

    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

  • BenWu
    Avatar
    Community Member
    87 Posts

    Re: gridField getCMSactions and summaryfields Link to this post

    regarding the 2nd question, it should be

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

  • martimiz
    Avatar
    Forum Moderator
    1037 Posts

    Re: gridField getCMSactions and summaryfields Link to this post

    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');
    }

    728 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.