Jump to:

5513 Posts in 1732 Topics by 1218 members

Customising the CMS

SilverStripe Forums » Customising the CMS » SS3 - canCreate/canDelete functions

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

Page: 1
Go to End
Author Topic: 739 Views
  • RuthAdele
    Avatar
    Community Member
    19 Posts

    SS3 - canCreate/canDelete functions Link to this post

    Hi guys,

    I like to stop pages from being created if there is already an instance of it, and likewise stop it from being deleted.
    Up until I started using Silverstripe 3 (last week), I've been using the following code:

    public function canCreate() {
       return false
    }
    public function canDelete() {
       return false
    }


    or

    public function canCreate() {
       return !DataObject::get_one($this->ClassName);
    }
    public function canDelete() {
       return !DataObject::get_one($this->ClassName);
    }

    However now it doesn't work with SS3. I get the following error:
    [Strict Notice] Declaration of HomePage::canCreate() should be compatible with that of SiteTree::canCreate()

    Does anyone know how I can get the same functionality in SS3?

    Thanks in advance,
    Ruth.

  • simon_w
    Avatar
    Forum Moderator
    471 Posts

    Re: SS3 - canCreate/canDelete functions Link to this post

    That functionality still works, you just need to have method decelerations be compatible with those you're overriding. Usually, this just means have the same prototype.

    In this case, that's

    public function canCreate($member = null)

    .

  • RuthAdele
    Avatar
    Community Member
    19 Posts

    Re: SS3 - canCreate/canDelete functions Link to this post

    Ah, thankyou very much!

    739 Views
Page: 1
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.