Question

I've seen a few things floating around the impermanent internet (i.e. Twitter) that some recent changes to Magento 2 make it possible to install a module into the vendor directory via composer, and Magento 2 will see your module without any symlink-ing tomfoolery.

If this is true, is there a "minimum composer.json" file floating about for module developers to use with their modules to let Magento 2 users install them into their systems?

Was it helpful?

Solution 2

It looks like something like this should do the trick.

{
    "name": "pulsestorm/module-name",
    "description": "A description of your extension",
    "authors": [
        {
            "name": "Robert Hoffner",
            "email": "rhoffner@example.com"
        }
    ],
    "require": {},
    "autoload": {
        "psr-4": {
            "Package\\Module\\": "src/path/to/Package/Module/Package/Module",
        },        
        "files": [
            "src/path/to/Package/Module/registration.php",
        ]
    }    
}

The key here is the autoloader section. It sets up up a PSR-4 autoloader that points at your class files, and automatically loads your registration.php. When composer drops the files in vendor and re-generated the autoload files, Magento should be able to see your module.

One neat side effect of this -- code no longer needs to be in app/code!

OTHER TIPS

Update

It looks like several things changed with some latest changes (October 7th) in the develop branch. It now looks like it's possible to support a module living in the vendor directory.

I created two examples of installing modules. One that copies files to app/code and another that registers the module where it resides in the vendor directory.

Copy Strategy: https://github.com/mttjohnson/magento2-sample-module-minimal-copy Registration Strategy: https://github.com/mttjohnson/magento2-sample-module-minimal-register

For development purposes I think utilizing the registration strategy is more useful because the files that are being run by Magento can be directly modified, tested and then committed back to the module repo.

Original Answer

If you have a composer.json file for your module composer package that contains a type of magento2-module then by default files will get copied over to a specified mapped directory in the app/code directory.

{
    "name": "vendorname/module-name",
    "type": "magento2-module",
    "require": {
        "magento/magento-composer-installer": "*"
    },
    "extra": {
        "map": [
            [
                "module",
                "VendorName/ModuleName"
            ]
        ]
    }
}

In this example composer.json the composer package name vendorname/module-name will result in the files for the composer package getting placed in vendor/vendorname/module-name.

The special type of magento2-module is implemented as a composer-plugin in the magento/magento-composer-installer package. That is why I have listed it in the require section. It is this composer-plugin that does the copying of files over into the appropriate magento app/code directory.

The extra: {map: [["composerDir","MagentoDir"]]} section is referenced by the composer-plugin installer to know what part of your composer package to map to what part of your magento directory structure. In the example provided this would take vendor/vendorname/module-name/module and copy files from there to app/code/VendorName/ModuleName.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top