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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

DataObjectDecorator adding fields to tabs


Go to End


2 Posts   2065 Views

Avatar
DanStephenson

Community Member, 116 Posts

30 September 2011 at 9:30am

Edited: 30/09/2011 9:31am

Hello,

I am trying to Decorate the EventCalendar module. I've created the following class:

<?php
class CustomCalendarEvent extends DataObjectDecorator {
    function extraStatics() {
        return array(
            'db' => array(
			   'Location' => 'Text',
			   'ShortDesc' => 'Text',
			   'MarketingMessage' => 'Text',
            ),
            'has_one' => array(
			   'FullImage' => 'Image',
			   'Thumb' => 'Image'
            ),
        );
    }
	
	public function getCMSFields() {
		$this->extend('updateCMSFields', $fields);
		return $fields;
	}
	
	public function updateCMSFields(FieldSet $fields) {
		$fields->push(new TextField('Location', 'Event Location'));
		$fields->push(new TextField('ShortDesc', 'Short Description'));
		$fields->push(new TextField('MarketingMessage', 'Marketing Message'));
		$fields->push(new ImageField('FullImage', 'Full Image'));
		$fields->push(new ImageField('Thumb', 'Thumbnail Image'));
	}
}

How can I make the new fields show up inside the CMS fields - such as Content.Main or a new Content.Images?

Avatar
jaybee

Community Member, 49 Posts

9 October 2011 at 12:33am

Try the following:

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

or

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