Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » DataObjectManager & Has Many File Manager - Limit # of entries?

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 3071 Views
  • DanStephenson
    Avatar
    Community Member
    115 Posts

    DataObjectManager & Has Many File Manager - Limit # of entries? Link to this post

    Hello,

    I am building a site that contains many types of data, and I really like the way DataObjectManager handles working with data in the CMS. However, for some of my fields, the user is only able to upload a set number (or less) of a certain type of data.

    For example - on a products page, the user may upload 4 or less (or none) videos per product.

    How can I setup DataObjectManager to only allow for a fixed number of maximum inputs?

    How can I do the same thing for has many file manager?

  • UncleCheese
    Avatar
    4085 Posts

    Re: DataObjectManager & Has Many File Manager - Limit # of entries? Link to this post

    Here's an interesting approach..

    $perms = array('edit','delete');
    if($this->FileObjects()->Count() < 4) $perms[] = 'add';
    $manager->setPermissions($perms);

  • DanStephenson
    Avatar
    Community Member
    115 Posts

    Re: DataObjectManager & Has Many File Manager - Limit # of entries? Link to this post

    Thanks Uncle Cheese. Where would I go about putting that code?

  • UncleCheese
    Avatar
    4085 Posts

    Re: DataObjectManager & Has Many File Manager - Limit # of entries? Link to this post

    In your getCMSFields() function.

    And, you know all the variable names and property names are examples, right? I can't tell you how many people try to use my example code in production.

  • DanStephenson
    Avatar
    Community Member
    115 Posts

    Re: DataObjectManager & Has Many File Manager - Limit # of entries? Link to this post

    Yeah, I know that. I just didn't know if it went into the CMSFields() function, or I created a new function inside my datatype.

  • schellmax
    Avatar
    Community Member
    126 Posts

    Re: DataObjectManager & Has Many File Manager - Limit # of entries? Link to this post

    the approach posted by UncleCheese (modifying the $perms array) is nice, it has a serious usability downside though:
    whenever you delete your latest object, you still can't add another one, as the permissions don't update. they DO update when you add another object though.

    so: having 3 objects and 4 are allowed, and you add a 4th, the 'add' button disappears as intended.
    but having 4 and deleting 1 won't result in the add button 'reappering' until you refresh the page.

    hope this is understandable

  • UncleCheese
    Avatar
    4085 Posts

    Re: DataObjectManager & Has Many File Manager - Limit # of entries? Link to this post

    Yeah, that makes sense. Although, you wouldn't have to refresh the entire page. You could just refresh the DataObjectManager itself. But I do see the issue. Deleting is the only action that does not refresh the entire DataObjectManager field.

  • schellmax
    Avatar
    Community Member
    126 Posts

    Re: DataObjectManager & Has Many File Manager - Limit # of entries? Link to this post

    could you set up dataobjectmanager to refresh after deleting an item / are there reasons not to do so?

    i also got an somewhat related issue:
    whenever i make some changes to an item in dataobjectmanager, and want to switch to another page, silverstripe brings up a javascript alert ('WARNING your changes have not been saved'), which is quite annoying, as changes have of course gracefully been saved by dataobjectmanager. is there a way to circumvent this?

    3071 Views
Page: 1 2
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.