Jump to:

23459 Posts in 18906 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » remove "Add" button from complexTable in cms (solved)

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

Page: 1
Go to End
Author Topic: 1054 Views
  • prawnstar
    Avatar
    Community Member
    116 Posts

    remove "Add" button from complexTable in cms (solved) Link to this post

    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

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

    Re: remove "Add" button from complexTable in cms (solved) Link to this post

    just a guess but add...

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

    ...to the data object?

  • prawnstar
    Avatar
    Community Member
    116 Posts

    Re: remove "Add" button from complexTable in cms (solved) Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: remove "Add" button from complexTable in cms (solved) Link to this post

    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.

  • prawnstar
    Avatar
    Community Member
    116 Posts

    Re: remove "Add" button from complexTable in cms (solved) Link to this post

    Thanks Will!

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

    fixed it!

    1054 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.