How do I extend CMS Block on save event of Magento?

How do I extend CMS Block on save event of Magento?

October 17, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How do I extend CMS Block on save event of Magento?

Extending CMS Block on Save Event in Magento

Introduction

In this guide, we’ll troubleshoot an issue related to extending the cms_block_save_before event in Magento, which isn’t triggering the desired method within your custom module.

Understanding the Current Setup

You have two key components:

  1. An XML configuration file located at app/code/local/Alchemy/Catalog/etc/config.xml. This file defines observers for various events, including catalog_product_save_after, catalog_category_save_after, and cms_block_save_before.

  2. A custom model Alchemy_Catalog_Model_Block that extends the core Mage_Cms_Model_Block.

However, the observer method rabbitmqBlockProducer() within your model is not being called when saving a CMS block.

The Issue at Hand

The primary problem lies in how you’ve configured your observer. Let’s take a closer look:

<cms_block_save_before>
  <observers>
    <Alchemy_Catalog>
      <type>singleton</type>
      <class>Alchemy_Catalog_Model_Block</class>
      <method>rabbitmqBlockProducer</method>
    </Alchemy_Catalog>
  </observers>
</cms_block_save_before>

The Solution Approach

To resolve this issue, we need to ensure that the observer is correctly configured and that the event prefix matches in both your model and the XML configuration.

Step-by-Step Fix

Step 1: Update the Event Prefix in Your Model

Currently, you have set the _eventPrefix property incorrectly:

protected $_eventPrefix = 'cms_block';

This should match the event name defined in your XML. However, since cms_block_save_before includes the “before” suffix, we need to adjust this:

Change it to:

protected $_eventPrefix = 'cms_block_save';

Step 2: Update the Observer Configuration

In your config.xml, ensure that the observer is configured correctly. The <method> attribute should correspond to a method that handles the event before it’s saved.

Change your XML configuration for cms_block_save_before to:

<cms_block_save_before>
  <observers>
    <Alchemy_Catalog>
      <type>singleton</type>
      <class>Alchemy_Catalog_Model_Block</class>
      <method>beforeSave</method>
    </Alchemy_Catalog>
  </observers>
</cms_block_save_before>

Step 3: Create the Handling Method in Your Model

Now, create a method in your Alchemy_Catalog_Model_Block class that will handle the cms_block_save_before event:

public function beforeSave($observer)
{
    Mage::log('CMS Block save before event triggered', null, 'marian.log');
    // Your rabbitmq logic here
}

Verifying the Solution

After implementing these changes, when you save a CMS block in your Magento admin panel, you should see a log entry matching the message from the beforeSave() method.

Remember to clear any previous cache and run a manual flush to ensure the new configuration is applied: php shell/indexer.php reindexall.

Conclusion

In this guide, we identified and resolved an issue related to extending Magento’s CMS block save events. The key takeaways include:

  1. Ensuring consistency between the event prefix in your model and the XML configuration.
  2. Creating a method in your model that handles the specific event being observed.
  3. Updating the observer configuration to point to the correct handling method.

This approach should help you successfully extend Magento’s built-in events for custom functionality, such as integrating with external services like rabbitmq.

For more advanced techniques and best practices in Magento development, consider exploring the resources available at Laravel Company.

Catalog Extensions Configuration Errors

Our network