0

First of all, I'm attempting to tap into the pre-deletion events of the following:

  1. Categories
  2. Products
  3. CMS Pages

Categories and products are fairly straight-forward, tapping the catalog_category_controller_category_delete and catalog_product_delete_before events, respectively. CMS pages on the other hand are another story...

I've browsed the source code inside app/code/core/adminhtml/controllers/cms/PageController.php to find the following:

public function deleteAction()
{
    // check if we know what should be deleted
    if ($id = $this->getRequest()->getParam('page_id')) {
        $title = "";
        try {
            // init model and delete
            $model = Mage::getModel('cms/page');
            $model->load($id);
            $title = $model->getTitle();
            $model->delete();
            // display success message
            Mage::getSingleton('adminhtml/session')->addSuccess(
                Mage::helper('cms')->__('The page has been deleted.'));
            // go to grid
            Mage::dispatchEvent('adminhtml_cmspage_on_delete', array('title' => $title, 'status' => 'success'));
            $this->_redirect('*/*/');
            return;

        } catch (Exception $e) {
            Mage::dispatchEvent('adminhtml_cmspage_on_delete', array('title' => $title, 'status' => 'fail'));
            // display error message
            Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
            // go back to edit form
            $this->_redirect('*/*/edit', array('page_id' => $id));
            return;
        }
    }
    // display error message
    Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('Unable to find a page to delete.'));
    // go to grid
    $this->_redirect('*/*/');
}

There is no indication that there is any event emitted prior to deleting a CMS page, nor does there appear to be any way to retrieve which CMS page ID has been deleted. Am I missing something or is this just another instance of Magento's excessive inconsistency?

1

I've implemented a (hopefully) temporary workaround by tapping into the controller_action_predispatch_adminhtml_cms_page_delete to accomplish the goal, however I'd like to see a more consistent solution if anyone has something clever to add.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.