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.

Data Model Questions /

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

Extending module using DataExtension


Go to End


2 Posts   1313 Views

Avatar
hschillig

Community Member, 5 Posts

21 November 2014 at 3:56am

Edited: 21/11/2014 3:59am

I'm trying to add another field into a module so I can sort by a different column and allow the user more control over how the content is ordered. I have this so far in mysite/code/ExtendedForum.php:

class ExtendedForum extends DataExtension {

	private static $db = array(
		'StackableOrder' => 'Int'
	);

	public function updateCMSFields(FieldList $fields) {

		$fields->addFieldToTab('Root.Main', new TextField("StackableOrder", "Order Page Appears In"), "Content");

	}

}

Then I added this into my config:

DataObject::add_extension('Forum', 'ExtendedForum');

It added the "StackableOrder" column into the database, but the field will not show in the CMS. It will only show if I use $fields->push(), but I don't want to use that because I want it to come after a certain column and every time I use push, the CSS is really jagged and the text appears right against the left side of the content instead of padded like the other fields and appears in every single tab... which I only want it to be in the Root.Main tab. If I get rid of the third parameter in the AddFieldToTab() it works fine.. but it appears as the very last field. The third parameter should place it above the field you specify which "Content" should work correct?

Thanks for any help!

Avatar
luuk

Community Member, 15 Posts

26 November 2014 at 8:37pm

Edited: 26/11/2014 8:40pm

try this:

public function updateCMSFields(FieldList $fields) {
   $fields->addFieldToTab('Root.Main', new TextField("StackableOrder", "Order Page Appears In"), "Content");
   return $fields;
}

and indeed, de third parameter manages the place where the field will come. In this case it should come before the Content field.