Skip to content

Module loading

ProcessEight edited this page Jan 27, 2021 · 1 revision

Module loading

Module load order can be influenced by defining sequnce nodes in any module.xml.

@todo Does defining other modules in composer.json require affect the load order?

The sorted order of modules is then written to app/etc/config.php.

@todo Does app/etc/config.php represent the final sorted load order of modules then? Verify this.

Theory/High Level Architectural Overview

The role of the sequence node

Module load order can be affected by the sequence node.

When a component (module/theme/setup/language/library) is added as children to the sequence node, they will be loaded before the module.

Module sequence-ing affects the load order of config XML, layout XML, view files (CSS, Less, template files) and resource classes. Note that it is only resource PHP classes which are affected, the loading of all other PHP classes are not affected.

As a rule of thumb,

How are modules loaded?

Given this module.xml file:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_ComponentB" setup_version="0.0.1">
        <sequence>
            <!-- Vendor_ComponentB is dependent on Vendor_ComponentA: -->
            <module name="Vendor_ComponentA" />
        </sequence>
    </module>
</config>

The load order of components would be:

  • Anything that Vendor_ComponentA requires (i.e. Anything that Vendor_ComponentA defines in its sequence node) is loaded first.
  • Anything in Vendor_ComponentA is loaded
  • Anything in Vendor_ComponentB is loaded

Modules are loaded in alphabetical order initially.

Then they are sorted into 'buckets', according to Magento_ vendor name.

They are then sorted by the order of sequence nodes.

How are modules sorted? How is the app/etc/config.php created and sorted?

Whenever a sequence node is edited, app/etc/config.php must be updated, by running bin/magento module:enable {{MODULE_NAME}}