7911 Posts in 1354 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » DataObjectManager: canCreate()
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 1488 Views |
-
DataObjectManager: canCreate()

2 August 2010 at 4:27am
How should I use canCreate()? Where should I put the function? I don't want ANYBODY to be able to add items.
<?php
class SliderItem extends DataObject
{
static $db = array (
'Link' => 'Varchar',
);static $has_one = array(
'Page'=>'Page'
);static $defaults = array(
"LinkText" => 'View Details',
);public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Link'),
);
}public function canCreate() {
return false;
}}
?>
-
Re: DataObjectManager: canCreate()

2 August 2010 at 12:09pm
That is the correct place for the function and the correct format. Is it still allowing you to add objects?
-
Re: DataObjectManager: canCreate()

2 August 2010 at 12:20pm
Yes, it is still allowing the administrator to add objects (SliderItem) using the DataObjectManager module.
-
Re: DataObjectManager: canCreate()

25 August 2010 at 10:11pm
Hi guys,
I need help on removing add and delete buttons from DataObjectManager. But I want to do this in a decorator class.
So in the owner class this is the code:
>>>
public function getCMSFields() {$fields = parent::getCMSFields();
$dataObjectManager = new DataObjectManager(
$this,
'HostingToplistItems',
'HostingToplistItem',
array(
'getSortOrder' => 'Rank',
'getProviderName' => 'Provider',
'getPlanName' => 'Plan',
'getEnabled' => 'Enabled'
)
);
}>>
Of course I can remove add and delete buttons by just putting the line $dataObjectManager->setPermissions(array(''));
But as ive mentioned I want to do this in the decorator class like
>>
public function updateCMSFields( FieldSet &$fields ) {
$this->owner->dataObjectManager->setPermissions(array(''))>>
I have declared $dataObjectManager in the owner class as public. The decorator class doesn't recognize $dataObjectManager.Any ideas how do this?
Thanks in advance!
-
Re: DataObjectManager: canCreate()

26 August 2010 at 1:48am
Did you try:
public function updateCMSFields( FieldSet &$fields ) {
$fields->fieldByName('HostingToplistItems')->setPermissions(array());
} -
Re: DataObjectManager: canCreate()

26 August 2010 at 2:08am
Yes, I did try that. I encountered this error
>>
Fatal error: Call to a member function setPermissions() on a non-object .. -
Re: DataObjectManager: canCreate()

26 August 2010 at 3:01am
Weird. Well, then just loop through the fields until you find the DOM and set the permissions on it.
| 1488 Views | ||
| Go to Top | Next > |



