Close [x]

Component load order

Edit this page on GitHub

Component load order

You may need to specify your component鈥檚 dependency on other components or files from other components using your component鈥檚 composer.json. Further, you can specify a load order in your component鈥檚 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鈥檚 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鈥檚 logic depends on something in another component then you should add it to require in composer.json and <sequence> in module.xml.

If you change the component load order using <sequence>, you must regenerate the component list in config.php; otherwise, the load order does not take effect.

Currently, the only way to do this is to enable the component using magento module:enable <module-list>, where <,pdi;e-list> is the component or components to which you added <sequence>.

Examples

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

Component A introduces gadgetlayout.xml, which updates block gadgetBlock from component B. In this case, layout files from component A should be loaded before component B, so you should specify that in component B鈥檚 <sequence> entry in module.xml.

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

In another scenario, let鈥檚 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鈥擡ither we don鈥檛 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鈥擫oads after component B because component B is listed in component A鈥檚 <sequence> tag.
  4. component Z/view/frontend/layout/default.xml鈥擡ither we don鈥檛 care about the sequence for component Z or perhaps component Z requires component A files to be loaded before it.

There are no limitations鈥攜ou 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鈥檚 composer.json file.

Take care when using <sequence> in multiple components because it's possible to define circular dependencies. If you do, Magento aborts the installation when it detects the circular dependency.

Next

Enable or disable a module