|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +group: extension-dev-guide |
| 4 | +subgroup: 3_Build |
| 5 | +title: Component registration |
| 6 | +menu_title: Component registration |
| 7 | +menu_order: 4 |
| 8 | +github_link: extension-dev-guide/composer-integration.md |
| 9 | +redirect_from: /guides/v1.0/extension-dev-guide/composer-integration.html |
| 10 | + |
| 11 | +--- |
| 12 | +##{{page.menu_title}} |
| 13 | + |
| 14 | + |
| 15 | +Magento components, including modules, themes, and languages, must be registered in the Magento system through the Magento `ComponentRegistrar` class. |
| 16 | + |
| 17 | +Each component must have a file called `registration.php` in its root directory. For example, here is the `registration.php` file for Magento's [AdminNotification module](https://github.corp.ebay.com/magento2/magento2ce/blob/develop/app/code/Magento/AdminNotification/registration.php). Depending on the type of component, registration is performed through `registration.php` by adding to it as follows: |
| 18 | + |
| 19 | +###Modules |
| 20 | + |
| 21 | +Modules are registered with: |
| 22 | + |
| 23 | + ComponentRegistrar::register(ComponentRegistrar::MODULE, '<VendorName_ModuleName>', __DIR__); |
| 24 | + |
| 25 | +where <VendorName> is the name of the company providing the module and <ModuleName> is the name of the module. |
| 26 | + |
| 27 | +#####Example |
| 28 | + ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_AdminNotification', __DIR__); |
| 29 | +<p> </p> |
| 30 | + |
| 31 | + |
| 32 | +###Themes |
| 33 | + |
| 34 | +Themes are registered with: |
| 35 | + |
| 36 | + ComponentRegistrar::register(ComponentRegistrar::THEME, '<area>/<vendor>/<theme name>', __DIR__); |
| 37 | + |
| 38 | +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. |
| 39 | + |
| 40 | + |
| 41 | +#####Example |
| 42 | + ComponentRegistrar::register(ComponentRegistrar::THEME, 'frontend/Magento/luma', __DIR__); |
| 43 | + |
| 44 | +<p> </p> |
| 45 | + |
| 46 | + |
| 47 | +###Languages |
| 48 | +Languages are registered with: |
| 49 | + |
| 50 | + ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, '<VendorName>_<packageName>', __DIR__); |
| 51 | + |
| 52 | +where <VendorName> is the name of the company providing the package and <packageName> is the name of the package. |
| 53 | + |
| 54 | +#####Example |
| 55 | + ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'magento_de_de', __DIR__); |
| 56 | + |
| 57 | +<p> </p> |
| 58 | + |
| 59 | +###Invoke registration.php in composer.json |
| 60 | + |
| 61 | +After you create your `registration.php` file and you are creating [your module's composer.json file](create_module.html#add-the-module8217s-composerjson-file), remember to invoke your `registration.php` file in the autoload section of `composer.json`: |
| 62 | + |
| 63 | + { |
| 64 | + "name": "Acme-vendor/bar-component", |
| 65 | + "autoload": { |
| 66 | + "psr-4": { "AcmeVendor\\BarComponent\\": "" }, |
| 67 | + "files": [ "registration.php" ] |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +<p> </p> |
| 72 | + |
| 73 | +##Sample registration.php file |
| 74 | + |
| 75 | +{% highlight php startinline=true %} |
| 76 | + <?php |
| 77 | +/** |
| 78 | +* Copyright © 2015 Magento. All rights reserved. |
| 79 | +* See COPYING.txt for license details. |
| 80 | +*/ |
| 81 | +\Magento\Framework\Component\ComponentRegistrar::register( |
| 82 | + \Magento\Framework\Component\ComponentRegistrar::MODULE, |
| 83 | + 'Magento_AdminNotification', |
| 84 | + __DIR__ |
| 85 | +); |
| 86 | + |
| 87 | +{%endhighlight %} |
| 88 | + |
| 89 | +##Next |
| 90 | + |
| 91 | +[Create a module](create_module.html) |
0 commit comments