By sun on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
In Drupal 8, only procedural code for e.g. hooks and theme functions remains in .module and .profile files.
Various modules and installation profiles do not have a use-case for implementing hooks or any procedural code. Therefore,
.moduleand.profilefiles are optional in Drupal 8. It is no longer required to create an empty PHP file.- all extensions are solely discovered based on their
.info.ymlfiles only.
To make this possible, the values of ModuleHandler::getModuleList() and ModuleHandler::setModuleList() have changed:
Instead of a list of pathnames, each array element is an instance of Drupal\Core\Extension\Extension now.
Drupal 7
foreach (module_list() as $name) {
$path = drupal_get_path('module', $name);
// yields e.g. 'modules/node'
$infofile = $path . '/' . $name . '.info';
// yields e.g. 'modules/node/node.info'
$pathname = drupal_get_filename('module', $name);
// yields e.g. 'modules/node/node.module'
}
Drupal 8
foreach (\Drupal::moduleHandler()->getModuleList() as $name => $module) {
$path = $module->getPath();
// yields e.g. 'modules/node'
$infofile = $module->getPathname();
// yields e.g. 'modules/node/node.info.yml'
$pathname = $module->getExtensionPathname();
// yields e.g. 'modules/node/node.module'
// NOTE: Returns NULL if there is no .module or .profile file.
$filename = $module->getExtensionFilename();
// yields e.g. 'node.module'
// NOTE: Returns NULL if there is no .module or .profile file.
}
Impacts:
Module developers