Jump to:

5554 Posts in 1742 Topics by 1227 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Removing the ‘Delete from the draft site’ button for published pages.

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

Page: 1 2
Go to End
Author Topic: 2706 Views
  • wdi2
    Avatar
    Community Member
    10 Posts

    Removing the ‘Delete from the draft site’ button for published pages. Link to this post

    Hi,

    I want to remove the ‘Delete from the draft site’ button for published pages. (i.e. I only want this button present if the user has unpublished the page)

    This is the code (in cms/code/CMSMain.php) that adds the button, I need to include in the if condition that the record is unpublished.

    else {
       if($record->canEdit()) {
          $actions->push($deleteAction = new FormAction('delete',_t('CMSMain.DELETE','Delete from the draft site')));
          $deleteAction->addExtraClass('delete');
       }

    Does anyone know how I would code $record-> is unpublished?

    Many Thanks

    Billy

  • UncleCheese
    Avatar
    4085 Posts
  • UncleCheese
    Avatar
    4085 Posts

    Re: Removing the ‘Delete from the draft site’ button for published pages. Link to this post

    Also, you don't need to mod the core code. Just add the method getAllCMSActions() to your model class.

  • wdi2
    Avatar
    Community Member
    10 Posts

    Re: Removing the ‘Delete from the draft site’ button for published pages. Link to this post

    Thanks UncleCheese

    got it sorted

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Removing the ‘Delete from the draft site’ button for published pages. Link to this post

    hi wdi2

    any chance you could post your final code for people who might be interested

    cheers

  • wdi2
    Avatar
    Community Member
    10 Posts

    Re: Removing the ‘Delete from the draft site’ button for published pages. Link to this post

    No probs, I should have done that

    Added the following in Sapphier/core/model/SiteTree.php
    ----------------------------------------------------------------------------------------------
       function getCMSActions() {
          $actions = array();
          
          if(!$this->isPublished()) {
             $deletedraft = FormAction::create('delete',_t('CMSMain.DELETE','Delete from the draft site'), 'delete');
             $deletedraft->addExtraClass('delete');
             $actions[] = $deletedraft;
          }

    -------------------------------------------------------------------------------------------------

    removed the following in cms/code/CMSMain.php
    -------------------------------------------------------------------------------------------------
    // getAllCMSActions can be used to completely redefine the action list
             if($record->hasMethod('getAllCMSActions')) {
                $actions = $record->getAllCMSActions();
             } else {
                $actions = new FieldSet();

                if($record->DeletedFromStage) {
                   if($record->can('CMSEdit')) {
                      $actions->push(new FormAction('revert',_t('CMSMain.RESTORE','Restore')));
                      $actions->push(new FormAction('deletefromlive',_t('CMSMain.DELETEFP','Delete from the published site')));
                   }
                } else {
                   /*if($record->canEdit()) {
                      $actions->push($deleteAction = new FormAction('delete',_t('CMSMain.DELETE','Delete from the draft site')));
                      $deleteAction->addExtraClass('delete');
                   }*/

    ------------------------------------------------------------------------------------------------------------------

    Updated Button name in cms/lang/en_US.php

    Not sure if this is the best way to get there, but it works.

  • Andrew Houle
    Avatar
    Community Member
    132 Posts

    Re: Removing the ‘Delete from the draft site’ button for published pages. Link to this post

    Did anyone figure out how to do this without moding the core? If so, could you please post your code that goes in the page model class here.

  • ejg
    Avatar
    Community Member
    1 Post

    Re: Removing the ‘Delete from the draft site’ button for published pages. Link to this post

    Thank you. After the third time my client deleted whole sections of their website and I had to muck around in the database to hook the pages back up, I decided I needed to remove the 'Delete from draft site' button for published pages.

    While my SiteTree.php was slightly different than what was posted, I was able to get it to work.

    How can there be such a catastrophic delete function without even a "Are you sure? confirmation dialog?

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