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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Example usage of updateCMSFields


Reply

5 Posts   2450 Views

Avatar
Jatinder

9 July 2010 at 10:57pm Community Member, 23 Posts

Hello,

Can anyone can give an example on how to use updateCMSFields?

Basically I need to add a new field to Member class. My current code:

class Client extends DataObjectDecorator {

   function extraStatics() {
      return array(
         'db' => array(
            'Phone' => 'Varchar'
         )
      );
   }

public function updateCMSFields(FieldSet &$fields) {
$fields->addFieldToTab('Root.Main', new TextField("Phone"));
}

}

The new field (Phone) shows up fine in add/edit popup forms. But I want to display this field in summary list also.

Thanks,
Jatinder Singh Thind

Avatar
Willr

10 July 2010 at 11:02am Forum Moderator, 5511 Posts

For the summary field see the updateSummaryFields() function. http://api.silverstripe.org/2.4/sapphire/model/DataObjectDecorator.html#methodupdateSummaryFields

Avatar
Jatinder

10 July 2010 at 3:56pm Community Member, 23 Posts

Thanks for the reply. But how do I use updateSummaryFields?

I haven't been able to find any example usage of this method.

Avatar
Willr

10 July 2010 at 4:17pm Forum Moderator, 5511 Posts

If you want to see usage for any update* functions its useful to look at the parent * function. summaryFields returns an associative array of "Field" => "Name" so you simply add what you want to that array

function updateSummaryFields(&$fields) {
$fields['Phone'] = "Phone Number";
}

Also looks like you could extraStatics to overload the summary_fields list

function extraStatics() {
return array(
'db' => array(
'Phone' => 'Varchar'
),
'summary_fields' => array(
'Phone' => 'Phone Number'
)

);
}

Avatar
congii

18 January 2013 at 8:53pm Community Member, 6 Posts

Hi, How do you use that in SS3?

Thanks!