I just wanted to write my first Hello World extension in Magento2, but it wasn't that easy. The normal way in Magento is to create a <module>.xml in app/etc/modules. For example my extension should have the Name Lesti_HelloWorld, I would create app/etc/modules/Lesti_HelloWorld.xml with the following content:
<?xml version="1.0"?>
<config>
<modules>
<Lesti_HelloWorld>
<active>true</active>
<codePool>community</codePool>
<depends>
<Mage_Core/>
</depends>
</Lesti_HelloWorld>
</modules>
</config>
There is just a app/etc, but no modules directory. I searched a long time in the darkness and didn't find any place for those declared module files. I did take a look at one of the config.xml files. And all the information about depencies and the current state of the extension are in the config.xml file. In my example app/code/Mage/Cms/etc/config.xml:
<?xml version="1.0"?>
<!-- ... -->
<config>
<modules>
<Mage_Cms>
<version>2.0.0.0</version>
<active>true</active>
<depends>
<Mage_Core/>
<Mage_Page/>
</depends>
</Mage_Cms>
</modules>
<!-- ... -->
</config>
My idea, maybe Magento2 doesn't need those <module>.xml files anymore and finds the config.xml files by seaching in every folder. And exactly that happens. The function _getDeclaredModuleFiles in app/code/Mage/Core/ModelConfig/Loader/Modules.php finds every config.xml file in a etc directory.
protected function _getDeclaredModuleFiles()
{
$codeDir = $this->_dirs->getDir(Mage_Core_Model_Dir::MODULES);
$moduleFiles = glob($codeDir . DS . '*' . DS . '*' . DS . 'etc' . DS . 'config.xml');
if (!$moduleFiles) {
return false;
}
$collectModuleFiles = array(
'base' => array(),
'mage' => array(),
'custom' => array()
);
foreach ($moduleFiles as $v) {
$name = explode(DIRECTORY_SEPARATOR, $v);
$collection = $name[count($name) - 4];
if ($collection == 'Mage') {
$collectModuleFiles['mage'][] = $v;
} else {
$collectModuleFiles['custom'][] = $v;
}
}
$etcDir = $this->_dirs->getDir(Mage_Core_Model_Dir::CONFIG);
$additionalFiles = glob($etcDir . DS . 'modules' . DS . '*.xml');
foreach ($additionalFiles as $v) {
$collectModuleFiles['base'][] = $v;
}
return array_merge(
$collectModuleFiles['mage'],
$collectModuleFiles['custom'],
$collectModuleFiles['base']
);
}
It did took me a long time, but I have found it. The funny thing, Magento2 is also seaching for files in app/etc/modules. The old version also should work. Now I can create my config.xml in app/code/Lesti/HelloWorld/etc/config.xml with the current content.
<?xml version="1.0"?>
<config>
<modules>
<Lesti_HelloWorld>
<version>2.0.0.0</version>
<active>true</active>
<depends>
<Mage_Core/>
</depends>
</Lesti_HelloWorld>
</modules>
<!-- -->
</config>
After all, I did find that line in changelog:
* Moved declaration of modules from `app/etc/modules/<module>.xml` to `app/code/<pool>/<namespace>/<module>/config.xml`
In my eyes, that isn't right, the current implementation would never find such a file. The next step is the
Hello World extension.