7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Maximum 10 Items: DataObjectManager Module
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 787 Views |
-
Maximum 10 Items: DataObjectManager Module

15 July 2010 at 10:50am
Using the DataObjectManager Module, how can I limit the maximum number of items added to 10?
-
Re: Maximum 10 Items: DataObjectManager Module

15 July 2010 at 11:47am
function canCreate() {
return DataObject::get("SomeObject")->Count() < 10;
} -
Re: Maximum 10 Items: DataObjectManager Module

2 August 2010 at 2:14pm
Where should I put:
?function canCreate() {
return DataObject::get("SomeObject")->Count() < 10;
}Could I use something like this instead?
if (DataObject::get("yourDom")->Count() > 10) $yourDom->removePermission('add');
-
Re: Maximum 10 Items: DataObjectManager Module

2 August 2010 at 3:50pm
Yeah.. well, really, the DOM should respect the canCreate() function on your source class, but clearly this just a gap in the code, so in the interim, I would just use something like:
if($this->YourRelatedObjects()->Count() > 10)
$dom->removePermission('add'); -
Re: Maximum 10 Items: DataObjectManager Module

2 August 2010 at 11:40pm
Thanks. That successfully prevents more than the allowed number of items to be added however when you delete an item you can't add another until you refresh the admin page.
I am not sure if the other problem is a bug or if I am just putting the canCreate() function in the wrong place.
<?php
class SliderItem extends DataObject
{
static $db = array (
'Heading' => 'Varchar',
'Text' => 'Text',
'Link' => 'Varchar',
'LinkText' => 'Text',
);static $has_one = array(
'Image' => 'Crop250x167',
'Page'=>'Page'
);static $defaults = array(
"LinkText" => 'View Details',
);public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Heading'),
new TextareaField('Text'),
new TextField('Link'),
new TextField('LinkText','Link Text'),
new ImageField('Image')
);
}public function canCreate() {
return false;
}
}?>
-
Re: Maximum 10 Items: DataObjectManager Module

3 August 2010 at 1:01am
Yeah, delete doesn't refresh the page, so that's going to be an issue no matter what approach you use for canCreate(). I'm not sure if there's a reasonable solution for that one.
| 787 Views | ||
|
Page:
1
|
Go to Top |


