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


Go to End
Reply

12 Posts   1937 Views

Avatar
DeklinKelly

2 August 2010 at 4:27am Community Member, 197 Posts

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

2 August 2010 at 12:09pm Forum Moderator, 5511 Posts

That is the correct place for the function and the correct format. Is it still allowing you to add objects?

Avatar
DeklinKelly

2 August 2010 at 12:20pm Community Member, 197 Posts

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

Avatar
UncleCheese

2 August 2010 at 12:40pm 4085 Posts

$yourDom->removePermission('add');

Avatar
EzraNaj

25 August 2010 at 10:11pm Community Member, 11 Posts

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

26 August 2010 at 1:48am 4085 Posts

Did you try:

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

Avatar
EzraNaj

26 August 2010 at 2:08am Community Member, 11 Posts

Yes, I did try that. I encountered this error
>>
Fatal error: Call to a member function setPermissions() on a non-object ..

Avatar
UncleCheese

26 August 2010 at 3:01am 4085 Posts

Weird. Well, then just loop through the fields until you find the DOM and set the permissions on it.

Go to Top