Resolving Magento module dependencies without using the “depends” element
You might someday (or perhaps you already have) come across a case where you want one module to be loaded after another module, but don’t necessarily want it to depend on the other module. Reasons might be that one config value should override another (such as a model/block/controller rewrite), or one layout should be applied after another (such as to remove a block added by the former). There might not actually be a dependence, or perhaps adding a dependence would create a circular dependency. There are two possible solutions for this:
- Merge the two (or more) module .xml files manually into one .xml file with the proper XML element order.
- Name the .xml files (or symlinks a.la. modman) such that they sort alphabetically in the proper order.
The element order within a single file will be stable (SimpleXML), and Magento loads the files alphabetically except that those beginning with Mage_ come first. Problem solved.
Before: app/etc/modules/My_Module.xml app/etc/modules/Their_Module.xml After: app/etc/modules/50_Their_Module.xml app/etc/modules/60_My_Module.xml
Now “My_Module” is loaded after “Their_Module” so I can override their config and/or layout without modifying their files and without My_Module depending on Their_Module!