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

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


Reply


5 Posts   1106 Views

Avatar
prawnstar

Community Member, 127 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, 1808 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
prawnstar

Community Member, 127 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, 5513 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
prawnstar

Community Member, 127 Posts

25 July 2010 at 8:02am

Thanks Will!

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

fixed it!