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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

DataObjectManager & Has Many File Manager - Limit # of entries?

Go to End

10 Posts   3087 Views


29 April 2009 at 4:53pm (Last edited: 29 April 2009 6:48pm), Community Member, 115 Posts


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?


30 April 2009 at 2:16am 4085 Posts

Here's an interesting approach..

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


30 April 2009 at 3:24am Community Member, 115 Posts

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


30 April 2009 at 3:30am 4085 Posts

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. :)


30 April 2009 at 3:42am Community Member, 115 Posts

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.


6 May 2009 at 1:00am Community Member, 126 Posts

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


6 May 2009 at 1:56am 4085 Posts

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.


6 May 2009 at 3:08am Community Member, 126 Posts

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?

Go to Top