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   1064 Views

Avatar
prawnstar

23 July 2010 at 8:36am (Last edited: 25 July 2010 8:01am), Community Member, 116 Posts

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

23 July 2010 at 8:58am Forum Moderator, 1796 Posts

just a guess but add...

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

...to the data object?

Avatar
prawnstar

23 July 2010 at 9:35am Community Member, 116 Posts

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

24 July 2010 at 11:10pm Forum Moderator, 5511 Posts

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

25 July 2010 at 8:02am Community Member, 116 Posts

Thanks Will!

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

fixed it!