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.

General Questions /

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

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

remove "Add" button from complexTable in cms (solved)


Go to End


5 Posts   1543 Views

Avatar
digibrains

Community Member, 130 Posts

23 July 2010 at 8:36am

Edited: 25/07/2010 8:01am

I want to remove the "Add ..." Button from the CMS display for a page that belongs to a many-many relationship. I only want someone to be able to click the checkbox to associate the Model object, but not create a new Model object from this page.

I'm calling it like this:

$modulesTablefield = new ManyManyComplexTableField(
	$this,
	'Modules',
	'Module',
	array(
		'Title' => 'Title',
		'Headline' => 'Headline'
	),
	'getCMSFields_forPopup'
);
$fields->addFieldToTab('Root.Content.Module',$modulesTablefield);

EDIT
Adding the following code to the page controller removes the add button.

$modulesTablefield->setPermissions(array(
	'view'
));

Chris.b

Avatar
swaiba

Forum Moderator, 1899 Posts

23 July 2010 at 8:58am

just a guess but add...

function canAdd(){return false;}
function canCreate(){return false;}

...to the data object?

Avatar
digibrains

Community Member, 130 Posts

23 July 2010 at 9:35am

Thanks swaiba. That didn't work, but the idea is what I want. Actually I don't want to remove the button at the data object level, just from the display in the cms on certain page types.

But that has me looking in that direction now.

Thanks,

Chris.b

Avatar
Willr

Forum Moderator, 5523 Posts

24 July 2010 at 11:10pm

You can set the permissions of a CTF one of those being add. See http://doc.silverstripe.org/tablelistfield#permissions for an example of how to set it. In your case you probably want only view, maybe edit.

Avatar
digibrains

Community Member, 130 Posts

25 July 2010 at 8:02am

Thanks Will!

$modulesTablefield->setPermissions(array(
	'view'
));

fixed it!