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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

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


Go to End


10 Posts   4222 Views

Avatar
DanStephenson

Community Member, 116 Posts

29 April 2009 at 4:53pm

Edited: 29/04/2009 6:48pm

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?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

30 April 2009 at 2:16am

Here's an interesting approach..

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

Avatar
DanStephenson

Community Member, 116 Posts

30 April 2009 at 3:24am

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

Avatar
UncleCheese

Forum Moderator, 4102 Posts

30 April 2009 at 3:30am

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

Avatar
DanStephenson

Community Member, 116 Posts

30 April 2009 at 3:42am

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.

Avatar
schellmax

Community Member, 126 Posts

6 May 2009 at 1:00am

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

Avatar
UncleCheese

Forum Moderator, 4102 Posts

6 May 2009 at 1:56am

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.

Avatar
schellmax

Community Member, 126 Posts

6 May 2009 at 3:08am

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