Jump to:

5554 Posts in 1742 Topics by 1227 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Fixed Number of Items in a ComplexTableField

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

Page: 1
Go to End
Author Topic: 1008 Views
  • Silverfish
    Avatar
    Community Member
    59 Posts

    Fixed Number of Items in a ComplexTableField Link to this post

    Hi There,

    I am looking for a way to fix the number of items of a ComplexTableField within the CMS. I.e. I have a page thas has_many pages as teasers, and i want the authors to set exactly (or at least not more than) 5 teasers. I checked the reference but found no thing like $TeaserTable->maxItems = 5. Is there anything like this?

    As workaround, I tried to modify the authors user rights so they can't add or delete any items. (So the admin could set 5 of them and the the authors could change them, but not change their numbers). I added

    public function canDelete($Member = null)
    {
       return Permission::check('DELETE_TEASER');
    }

    to the Teaser Object, this worked. But

    public function canAdd($Member = null)
    {
       return Permission::check('ADD_TEASER');
    }

    shows no impact on the bottom 'Add Teaser' line of the table overview.

    Any Ideas?

    Thanks a lot for any hint!

    SF

  • martimiz
    Avatar
    Forum Moderator
    1091 Posts

    Re: Fixed Number of Items in a ComplexTableField Link to this post

    Shouldn't you use canCreate() instead of canAdd()?

    [EDIT]
    Just thinking: you could maybe subclass the ComplexTableField, then create a public method that sets the $permissions array (that is default set to add, edit, show, delete). See what that does?

    Would be nice if you could make it dynamic and test the number of items... But then I don't know if the add button would be updated when the complextablefield is reloaded in the cms after adding/removing an item...

  • Silverfish
    Avatar
    Community Member
    59 Posts

    Re: Fixed Number of Items in a ComplexTableField Link to this post

    canCreate() doesn't work neither .

    I thought of canAdd since print_r of the ComplexTableFied Object shows

    [permissions:protected] => Array
    (
    [0] => add
    [1] => edit
    [2] => show
    [3] => delete
    )


    somewhere.

    Thx anyway.

    SF

  • Silverfish
    Avatar
    Community Member
    59 Posts

    Re: Fixed Number of Items in a ComplexTableField Link to this post

    After reading http://doc.silverstripe.org/sapphire/en/reference/complextablefield the forth time, i finally discovered

    Use ComplexTableField->setPermissions(array("show","edit")) to limit the functionality without touching the template (more secure). Possible values are "show","edit", "delete" and "add".

    This solved at least the add-rights issue.

    regards
    SF

  • martimiz
    Avatar
    Forum Moderator
    1091 Posts

    Re: Fixed Number of Items in a ComplexTableField Link to this post

    Ah - I was looking for that method and just couldn't find it... That's why I came up with the vague idea to extend the class to create it. Guess I should have taken the time to read it four times as well

    1008 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.