Edit in GitHubLog an issue

Name a component

You give a name to your component in its composer.json and module.xml files. These files also contain other required configuration parameters, such as the module's schema version.

Prerequisites#

Before you continue, make sure you have completed all of the following tasks:

Add a module.xml file#

Declare the component itself by adding a module.xml file in the /etc folder of your component.

A component declares itself (that is, defines its name and existence) in the module.xml file, located in the install directory at <ComponentName>/etc/.

The smallest working module.xml file would look something like this:

Copied to your clipboard
1<?xml version="1.0"?>
2<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3 <module name="Vendor_ComponentName"/>
4</config>

The name parameter defines the name of your component. It is required for all components. If you do not use Declarative Schema to help manage the installation and upgrade processes for your component, then you must also add the setup_version parameter to the module line. Set the setup_version value to your module's database schema version. Omit the setup_version parameter if you use Declarative Schema.

Add a composer.json file#

composer.json provides a component name and also specifies component dependencies.

Refer to Module version dependencies to determine versioning requirements.

Example#

Copied to your clipboard
1{
2 "name": "your-name/module-Acme",
3 "description": "Test component",
4 "require": {
5 "php": "~7.3.0||~7.4.0",
6 "magento/module-store": "102.1",
7 "magento/module-catalog": "102.1",
8 "magento/module-catalog-inventory": "102.1",
9 "magento/module-ui": "self.version",
10 "magento/magento-composer-installer": "*"
11 },
12 "suggest": {
13 "magento/module-webapi": "102.1"
14 },
15 "type": "magento2-module",
16 "version": "102.1",
17 "license": [
18 "OSL-3.0",
19 "AFL-3.0"
20 ],
21 "autoload": {
22 "files": [ "registration.php" ],
23 "psr-4": {
24 "Magento\\CatalogImportExport\\": ""
25 }
26 }
27}

In this example:

  • name is the name of your component.
  • description is a concise explanation of your component's purpose.
  • require lists any components your component depends on.
  • suggest lists soft dependencies. The component can operate without them, but if the components are active, this component might impact their functionality. Suggest does not affect component load order.
  • type determines what the component type. Choose from magento2-theme, magento2-language, or magento2-module.
  • version lists the version of the component.
  • license lists applicable licenses that apply to your component.
  • autoload instructs Composer to load the specified files.
Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.