Name your component
Overview of naming 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:
- Created a file structure
- Created the the configuration files you’ll need
- Registered your component
Add the component’s 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 Magento install directory at <ComponentName>/etc/
.
The smallest working module.xml file would look something like this:
<?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_ComponentName" setup_version="2.0.0"/>
</config>
…where name
is the name of your component, and setup_version
is your module’s database schema version. Both of these attributes are required.
Do not use “Ui” for your custom module name because the %Vendor%_Ui
notation, required when specifying paths, might cause issues.
Add the components composer.json
file
composer.json
provides a component name and also specifies component dependencies.
In addition, the Component Manager looks for a composer.json
in a component’s root directory and can perform actions on the component and its dependencies.
In particular:
- If a component has
composer.json
and the component was installed using Composer (including from packagist, the Magento Marketplace, or other source), the Component Manager can update, uninstall, enable, or disable the component. - If the component has
composer.json
but was not installed using Composer (for example, custom code a developer wrote), Component Manager can still enable or disable the component. - We strongly recommend you include
composer.json
in your component’s root directory whether or not you intend to distribute it to other Magento merchants.
A sample follows:
where:
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 Magento 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.
Magento does not currently support the path
repository.