10

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.

14

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.

  • 3
    I'm curious if the observer merging process uses only the name attribute (seeing how it's unique). In which case, you could omit the somewhat long instance property: <observer name="aw_blog_add_topmenu_items" disabled="true". – nevvermind Apr 24 '16 at 10:59

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.