This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

How to Register Your Component in Magento 2 Using Registration.php File

Published on May 9, 2016 - Content Updated on December 23, 2021

2 Min Read

Building your component includes laying out the file structure, creating the necessary configuration files, working out any required API interfaces and services, and adding any frontend parts required for your component.

Before you start making your new component, make sure that you have a working installation of Magento 2.0 and disable Magento caching while you are setting up the component file structure and adding configuration files.

Registration.php Magento 2

In Magento 2 Components have two types of versions:

  • Marketing version
  • Composer version

After creating the components, you need to register them. We can register our components in the Magento system through the Magento componentRegister class.

Every component must have a file called registration.php in its root directory. For example, if you are creating an Image Gallery module and your component’s name is Your-Module, you must create registration.php in your component root. Depending on the type of component, registration is performed through registration.php by adding to it as follows:

Register Your Modules

You can register your Magento 2 module by using this code:

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

Where <YourVendorName> is the name of the main directory which you created for your module and <ModuleName> is the name of your module.

For example:

use \Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Cloudways_GalleryNotification', __DIR__);

Here I used Cloudways_Gallery as my vendor name and Notification is my module name.

Register Your Themes

You can register your Magento 2 theme by using this code:

ComponentRegistrar::register(ComponentRegistrar::THEME, '<area>/<yourvendor>/<yourtheme name>', __DIR__);

where <area> is the functional area of the module like frontend, controller, and etc, <yourvendor> is the name of the main directory name which you created for your theme, and <yourthemename> is the name of your theme.

For example:

ComponentRegistrar::register(ComponentRegistrar::THEME, 'frontend/Cloudways/m2-theme', __DIR__);

Here I used Cloudways as my vendor name and m2-theme is my theme name.

Register Your Language Packages

You can register your Magento 2 language packages by using this code:

ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, '<YourVendorName>_<YourpackageName>', __DIR__);

Where <YourVendorName> is the name of the main directory name which you created for your language and <YourpackageName> is the name of your package.

For example:

ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'magento_sp_sp', __DIR__);

After creating registration.php file and creating your component’s composer.json file, invoke your registration.php file in the autoload section of composer.json:

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

Here is the sample registration.php file:

<?php
use \Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(ComponentRegistrar::MODULE, ‘Cloudways_GalleryNotification’, __DIR__);
?>

Conclusion:

This is a short but very useful tutorial. By following the above steps, you can register your module, theme, and your language packages. If you feel some trouble in component registration do let me know in comments section. I’ll get back to you at the earliest.

Finally, don’t miss your chance to test out the most advanced Managed Magento Hosting Platform, Cloudways. Activate your free trial today.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Customer Review at

“Great speed, features, knowledgebase, dashboard, UX and fast, expert support. Very happy!”

Stefan [Management Consultant]

Cloudways

Cloudways is a European MSP that provides custom cloud design, deployment and management solutions on leading cloud providers.

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!