Edit in GitHubLog an issue

Component load order

You may need to specify your component's dependency on other components or files from other components using your component's composer.json. Further, you can specify a load order in your component's module.xml file using the <sequence> tag to ensure that needed files from other components are already loaded when your component loads.

<sequence> declares the list of components that must be loaded before the current component is loaded. It's used for loading different kind of files: configuration files, view files (including CSS, Less, and template files), or setup classes. Note that <sequence> does not affect the loading of regular classes (non-setup classes). Setup classes are classes in the component that create or update database schema or data.

If you know that your component's logic depends on something in another component, then you should add this component to require in composer.json and <sequence> in module.xml.

You can check your module's load order from the <magento_root>/app/etc/config.php file after you've successfully set up Magento. This file is created dynamically at run time during set up.

Examples

Assume you have a component that needs a configuration file from another component:

Component B introduces gadgetlayout.xml, which updates block gadgetBlock from component A. In this case, layout files from component A should be loaded before component B, so you should specify that in component B's <sequence> entry in module.xml. In other words, component B is dependent on component A. That is to say:

Copied to your clipboard
<?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">
<sequence>
<!-- Vendor_ComponentB is dependent on Vendor_ComponentA: -->
<module name="Vendor_ComponentA" />
</sequence>
</module>
</config>

For each particular scenario, files of the same type are loaded from different components taking into account the sequence information provided in each component's module.xml file.

In another scenario, let's say you want to load all of the layout files with the name default.xml. Component A specifies component B in <sequence>. The files load in the following order:

  1. component X/view/frontend/layout/default.xml---Either we don't care about when component X loads or perhaps component B requires it to be loaded before it.
  2. component B/view/frontend/layout/default.xml
  3. component A/view/frontend/layout/default.xml---Loads after component B because component B is listed in component A's <sequence> tag.
  4. component Z/view/frontend/layout/default.xml---Either we don't care about the sequence for component Z or perhaps component Z requires component A files to be loaded before it.

There are no limitations---you can specify any valid component in <sequence>.

If you do specify a component in <sequence>, make sure that you have also added it to the require section in that component's composer.json file.

  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.