Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » DataObjectManager: canCreate()

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 1864 Views
  • DeklinKelly
    Avatar
    Community Member
    197 Posts

    DataObjectManager: canCreate() Link to this post

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

    }

    ?>

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: DataObjectManager: canCreate() Link to this post

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

  • DeklinKelly
    Avatar
    Community Member
    197 Posts

    Re: DataObjectManager: canCreate() Link to this post

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

  • UncleCheese
    Avatar
    4085 Posts

    Re: DataObjectManager: canCreate() Link to this post

    $yourDom->removePermission('add');

  • EzraNaj
    Avatar
    Community Member
    11 Posts

    Re: DataObjectManager: canCreate() Link to this post

    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!

  • UncleCheese
    Avatar
    4085 Posts

    Re: DataObjectManager: canCreate() Link to this post

    Did you try:

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

  • EzraNaj
    Avatar
    Community Member
    11 Posts

    Re: DataObjectManager: canCreate() Link to this post

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

  • UncleCheese
    Avatar
    4085 Posts

    Re: DataObjectManager: canCreate() Link to this post

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

    1864 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.