Disabled Modules and Config.xml Rewrite Error
A really big problem we’ve recently come across here at e-commerce web design occurs when using a rewrite within a module to rewrite a block to use a different class.
For example in a recent extension we are developing we needed to override and extend the class of head.php, we did this by creating a config.xml for our extension and adding in the following XML:
<blocks> <page> <rewrite> <html_head>Company_Module_Block_Page_Html_Head</html_head> </rewrite> </page> </blocks>
The above code will tell Magento to load our custom block instead of the normal head block. In our custom block we are extending the normal one – so everything will work the same as normal apart from we’ll be able to use the new functions we have defined.
This all happens as expected. The block is extended and our new functions are being used. The problem occurs when the extension is disabled in the system>configuration>advanced tab.
Once an extension is disabled the blocks are no longer called. However the config.xml is still loaded – so Magento is still rewriting our head block causing Magento to try to load a block that it can no longer see (as our head block is essentially disabled).
This results in Magento not loading a head.php at all, resulting in empty <head></head> tags in the front-end of our website.
Now is usually the time when we turn around and say “Here’s the fix”. Unfortunately we haven’t got one. The only method we have come across to fix this is to disable the module by changing its <active>false</active> tag in the etc>modules>Company_Module.xml file.
It’s a bit of a major bug as I for one never disable a module through the xml file – I’m lazy and prefer to do it in the admin section. If anyone out there knows of a fix or a new way to rewrite a block and not have it destroy they website when disabling we’d be forever in your debt!
Thanks for visiting the Magento Blog!