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   2735 Views

Avatar
wdi2

Community Member, 10 Posts

27 January 2009 at 1:02pm

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

4085 Posts

27 January 2009 at 2:04pm

Try $record->Published()

Avatar
UncleCheese

4085 Posts

27 January 2009 at 2:10pm

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

Avatar
wdi2

Community Member, 10 Posts

29 January 2009 at 1:33pm

Thanks UncleCheese

got it sorted

Avatar
Carbon Crayon

Community Member, 598 Posts

29 January 2009 at 2:24pm

hi wdi2

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

cheers

Avatar
wdi2

Community Member, 10 Posts

1 February 2009 at 11:20pm

Edited: 01/02/2009 11:21pm

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

Community Member, 132 Posts

6 November 2009 at 5:27am

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

Community Member, 1 Post

4 February 2010 at 6:16am

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