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.


Reply


9 Posts   2736 Views

Avatar
pter

Community Member, 38 Posts

26 November 2010 at 8:03pm

I was also looking for the same sort of control, notably to force the use of requests in CMSworkflow so admins didn't just save and publish. Then it occurred to me that it would also be nice to remove delete from draft vs unpublish etc at strategic times. You've probably solved it somewhere else by now however:

<?php

/*
   extends SiteTree to remove some buttons from CMS at relevant times to force
   behaviour.

   * Save and Publish - always removed to force use of publication request when
      the CMSWorkflow module is installed. Comment out if not using module.
      Wonder if could check to see if CMSWorkflow there and automate.
   * Delete From Draft Site - removed when page is published to force unpublish
      before allowing delete from the site.
   * Unpublish - removed when page has unpublished changes to force cancellation
      of changes first. However as it seems to stay on 'changed in stage'
      even if you do the cancel draft changes and it copies in from the published version
      it still seems to return true for changed until published... so that has been
      commented out.

   add to site _config.php with Object::add_extension('SiteTree','RemoveCMSButtonsDecorator');
*/

class RemoveCMSButtonsDecorator extends DataObjectDecorator {

   public function updateCMSActions(&$actions) {
      $owner = $this->owner;
      $changed = $owner->getIsModifiedOnStage();
      $published = $owner->isPublished();

      $savepublishbutton = strtolower(_t('BUTTONSAVEPUBLISH','Save and Publish'));
      $unpublishbutton = strtolower(_t('BUTTONUNPUBLISH','Unpublish'));
      $deletedraftbutton = strtolower(_t('CMSMain.DELETE','Delete from the draft site'));

      foreach($actions as $anaction) {
         $title = strtolower($anaction->Title());
//         if ($changed && ($title == $unpublishbutton)) $actions->remove($anaction);
         if ($published && ($title == $deletedraftbutton)) $actions->remove($anaction);
//         if ($title == $savepublishbutton) $actions->remove($anaction);
      }
   }

}