Close [x]

Module configuration files

Edit this page on GitHub

Contents

Overview of module configuration files

The responsibilities of the config.xml configuration file used in earlier versions of Magento is now divided between several files, located in various module directories. Magento鈥檚 multiple configuration files load on demand only when a module requests a specific configuration type.

You can use these files鈥攁lso referred to as configuration types鈥攖o customize specific aspects of your module鈥檚 behavior.

Multiple modules can declare configuration files that affect the same configuration type (for example, events), and these multiple configuration files are merged.

Following are common terms used in this topic:

Configuration object
The Magento library or class that is responsible for defining and validating the configuration type. For example, the configuration object for config.xml is Magento\Framework\App\Config.
Configuration stage
Stages are defined as primary, global, and area. Each stage determines when configuration type is loaded and merged with same-named configuration types. (For example, module.xml files are merged with other module.xml files.) For more information, see Configuration load and merge.
Configuration scope
Complementary to a configuration stages, a scope defines the configuration type model. For example, adminhtml is an area scope that is loaded with at the stage with other modules' adminhtml configurations. For more information, see Modules and areas.

Configuration load and merge

This section discusses how configuration files are loaded and merged.

How Magento loads configuration files

Magento loads configuration files in the following order (all paths are relative to your Magento installation directory):

  • Primary configuration (app/etc/di.xml). This file is used to bootstrap Magento.
  • Global configurations from modules (<your component base dir>/<vendorname>/<component-type>-<component-name>/etc/*.xml). Collects certain configuration files from all modules and merges them together.
  • Area-specific configuration from modules (<your component base dir>/<vendorname>/<component-type>-<component-name>/etc/<area>/*.xml). Collects configuration files from all modules and merges them into the global configuration. Some area-specific configurations can override or extend the global configuration.

where

  • <your component base dir> is the base directory in which your component is located. Typical values are app/code or vendor relative to the Magento installation directory.
  • <vendorname> is the component鈥檚 vendor name; for example, Magento鈥檚 vendor name is magento.
  • <component-type> is one of the following:

    • module-: An extension or module.
    • theme-: Theme.
    • language-: Language package.

    Currently, themes are located under <your Magento install dir>/app/design/frontend or <your Magento install dir>/app/design/adminhtml

  • <component-name>: Name of your component as defined in composer.json.

Configuration file merge

Nodes in configuration files are merged based on their fully qualified XPaths, which has a special attribute defined in $idAttributes array declared as its identifier. This identifier must be unique for all nodes nested under the same parent node.

Magento鈥檚 merge algorithm follows:

  • If node identifiers are equal (or if there is no identifier defined), all underlying content in the node (attributes, child nodes, and scalar content) is overridden.
  • If node identifiers are not equal, the node is a new child of the parent node.
  • If the original document has multiple nodes with the same identifier, an error is triggered because the identifiers cannot be distinguished.

After configuration files are merged, the resulting document contains all nodes from the original files.

Configuration types, objects, and interfaces

The following sections provide information about configuration types, their corresponding configuration objects, and interfaces you can use to work with the objects:

Configuration types and objects

The following table shows each configuration type and the Magento configuration object to which it relates.

Configuration file Description Stage Configuration object
config.php and env.php Deployment configuration Loads into memory when Magento initializes Has no object, cannot be customized
config.xml System configuration primary, global \Magento\Framework\App\Config
di.xml Dependency injection configuration primary, global, area \Magento\Framework\ObjectManager\Config
events.xml Event/observer configuration global, area \Magento\Framework\Event
routes.xml Route configuration area Magento\Framework\App\Route\Config

Configuration interfaces

You can interact with configuration files using interfaces under Magento\Framework\Config. You can also use these interfaces if you create a new configuration types.

Magento\Framework\Config provides the following interfaces: