Magento – Remove observer from third party extension

event-observermagento2overrides

I have installed a blog module onto my Magento 2 platform. This blog module has an observer which automatically adds a new menu item into the primary navigation. I wish to stop this.

The events.xml file looks like this:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="page_block_html_topmenu_gethtml_before">
        <observer name="aw_blog_add_topmenu_items" instance="Aheadworks\Blog\Observer\AddBlogToTopmenuItemsObserver" />
    </event>
</config>

As you can see it references the observer that adds the link into the primary navigation. Deleting events.xml solves my problem, but I'm looking for a method that doesn't involve modifying of core module files.

Best Answer

You still can disable observers. In Magento 1 it was done with <type>disabled</type>, in Magento 2 it's disabled="true":

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="page_block_html_topmenu_gethtml_before">
        <observer name="aw_blog_add_topmenu_items"
                  instance="Aheadworks\Blog\Observer\AddBlogToTopmenuItemsObserver"
                  disabled="true" />
    </event>
</config>

If you add this modified events.xml file to a custom module and make the custom module depend on Aheadworks_Blog, it should override the original one.