Home > Uncategorized > Resolving Magento module dependencies without using the “depends” element

Resolving Magento module dependencies without using the “depends” element

October 13th, 2011

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:

  1. Merge the two (or more) module .xml files manually into one .xml file with the proper XML element order.
  2. 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.

Example:

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!

Uncategorized

  • https://saferite.com/lee/ Lee Saferite

    I’d say this is an area ripe for a patch to core.  The config file should have perhaps an attribute on the depends child elements that says required=”false” or something similar.  Then the depends checks could still sort properly, but not blow up if you say it’s not required.

  • http://colin.mollenhour.com Colin Mollenhour

    I actually just submitted a pull request for Magento 2 the other day: https://github.com/magento/magento2/pull/19