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.

Customising the CMS

Removing the ‘Delete from the draft site’ button for published pages.


Go to End
Reply

9 Posts   2712 Views

Avatar
wdi2

27 January 2009 at 1:02pm Community Member, 10 Posts

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

Avatar
UncleCheese

27 January 2009 at 2:04pm 4085 Posts

Try $record->Published()

Avatar
UncleCheese

27 January 2009 at 2:10pm 4085 Posts

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

Avatar
wdi2

29 January 2009 at 1:33pm Community Member, 10 Posts

Thanks UncleCheese

got it sorted

Avatar
Carbon Crayon

29 January 2009 at 2:24pm Community Member, 598 Posts

hi wdi2

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

cheers

Avatar
wdi2

1 February 2009 at 11:20pm (Last edited: 1 February 2009 11:21pm), Community Member, 10 Posts

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.

Avatar
Andrew Houle

6 November 2009 at 5:27am Community Member, 132 Posts

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.

Avatar
ejg

4 February 2010 at 6:16am Community Member, 1 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?

Go to Top