0

Is it possible to sort the output of the modules node in config.php alphabetically? This way git versioning won't get messed up since Magento sometimes changes the sorting.

<?php
return [
    'modules' => [
        'Magento_ModuleA' => 1,
        'Magento_ModuleB' => 1,
        'Magento_ModuleC' => 1,
        ...

composer.json has an option for it, is there something similar for config.php?

"config": {
        "sort-packages": true

3 Answers 3

1

We can control the module load order using the sequence tag in module.xml.

<?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>

Easy for your reference: https://devdocs.magento.com/guides/v2.4/extension-dev-guide/build/module-load-order.html

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, where `module list is the component or components to which you added .

Note: Don't sort/change the core module load order, it will create issues. For example, core-module-a depends on core-module-b, core-module-a will not work properly if you didn't load core-module-b first.

1

Is it possible to sort the output of the modules node in config.php alphabetically?

The simple answer is no. The order of files in config.php is determined by the module load sequence in @Bilal's answer. This is critical to Magento's internal module loading logic and also sets the order in which configuration XML files are loaded and merged allowing DI, events, and all the other XML files in your etc directory, to modify other modules configuration.

0

There is a simple open source module for keeping sorting same for config.php here - https://github.com/zero1limited/magento2-PreserveModuleOrderingInProductionMode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.