Close [x]

Component registration

Edit this page on GitHub

Component registration

Magento components, including modules, themes, and languages, must be registered in the Magento system through the Magento ComponentRegistrar class.

Each component must have a file called registration.php in its root directory. For example, here is the registration.php file for Magento鈥檚 AdminNotification module. Depending on the type of component, registration is performed through registration.php by adding to it as follows:

Modules

Modules are registered with:

 ComponentRegistrar::register(ComponentRegistrar::MODULE, '<VendorName_ModuleName>', __DIR__);

where <VendorName> is the name of the company providing the module and <ModuleName> is the name of the module.

Example
 \Magento\Framework\Component\ComponentRegistrar::register(
     \Magento\Framework\Component\ComponentRegistrar::MODULE,
     'Magento_AdminNotification',
     __DIR__
 );

 

Themes

Themes are registered with:

 ComponentRegistrar::register(ComponentRegistrar::THEME, '<area>/<vendor>/<theme name>', __DIR__);

where <area> is the functional area of the module (frontend, controller, and so on.), <vendor> is the name of the company providing the theme, and <theme name> is the name of the theme.

Example
 ComponentRegistrar::register(ComponentRegistrar::THEME, 'frontend/Magento/luma', __DIR__);

 

Languages

Languages are registered with:

 ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, '<VendorName>_<packageName>', __DIR__);

where <VendorName> is the name of the company providing the package and <packageName> is the name of the package.

Example
 ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'magento_de_de', __DIR__);

 

Invoke registration.php in composer.json with autoload

After you create your registration.php file and you are creating your module鈥檚 composer.json file, remember to invoke your registration.php file in the autoload section of composer.json:

 {
"name": "Acme-vendor/bar-component",
"autoload": {
    "psr-4": { "AcmeVendor\\BarComponent\\": "" },
    "files": [ "registration.php" ]
} }

 

Sample registration.php file

<?php

use \Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_AdminNotification', __DIR__);

Next

Create a module