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: canCreate()


Go to End


12 Posts   3566 Views

Avatar
DeklinKelly

Community Member, 197 Posts

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;
	} 

}

?>

Avatar
Willr

Forum Moderator, 5523 Posts

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?

Avatar
DeklinKelly

Community Member, 197 Posts

2 August 2010 at 12:20pm

Yes, it is still allowing the administrator to add objects (SliderItem) using the DataObjectManager module.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

2 August 2010 at 12:40pm

$yourDom->removePermission('add');

Avatar
EzraNaj

Community Member, 11 Posts

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!

Avatar
UncleCheese

Forum Moderator, 4102 Posts

26 August 2010 at 1:48am

Did you try:

public function updateCMSFields( FieldSet &$fields ) {
$fields->fieldByName('HostingToplistItems')->setPermissions(array());
}

Avatar
EzraNaj

Community Member, 11 Posts

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

Avatar
UncleCheese

Forum Moderator, 4102 Posts

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.

Go to Top