drupal_system_listing()
, Drupal\Core\SystemListing
, and Drupal\Core\SystemListingInfo
have been replaced with a highly performance optimized Drupal\Core\Extension\ExtensionDiscovery
.
-
All Drupal extension types (profiles, modules, themes, theme engines) have to supply an
.info.yml
file in order to be discovered.- Each .info.yml file must specify at least the
'type'
,'core'
, and'name'
properties. - The
'type'
value for theme engines istheme_engine
. - The
'type'
property should ideally be declared first (for file parsing performance reasons only).
Example:
type: theme_engine core: 8.x name: Twig version: VERSION package: Core
- Each .info.yml file must specify at least the
-
drupal_system_listing()
has been replaced withDrupal\Core\Extension\ExtensionDiscovery
.Drupal 7
$available_modules = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.module$/', 'modules');
Drupal 8
$listing = new ExtensionDiscovery(); $available_modules = $listing->scan('module'); // The returned elements are instances of \Drupal\Core\Extension\Extension: $type = $available_modules['node']->getType(); // => 'module' $name = $available_modules['node']->getName(); // => 'node' $path = $available_modules['node']->getPath(); // => 'core/modules/node' $pathname = $available_modules['node']->getPathname(); // => 'core/modules/node/node.info.yml' $uri = $available_modules['node']->uri; // => 'core/modules/node/node.module' // Also offering access to \SplFileInfo of the .info.yml file: // @see http://php.net/manual/class.splfileinfo.php $filemtime = $available_modules['node']->getMTime();
-
drupal_system_listing()
was rarely used to discover arbitrary files in all extension directories. This generic facility is no longer supported, but can be re-implemented easily:Drupal 7
$providers = drupal_system_listing('/^discover\.me\.txt$/', 'modules');
Drupal 8
$subpathname = 'discover.me.txt'; // The file to discover in each extension directory. $listing = new ExtensionDiscovery(); $files = array(); foreach ($listing->scan('module') as $module) { if (file_exists($filepath = $module->getPath() . '/' . $subpathname)) { $files[$module->getName()] = $filepath; } }
However, bear in mind that this performs a raw filesystem scan that is not cached, and the results are not filtered to enabled/installed extensions. In almost all cases, it is better to rely on the list of enabled/installed extensions instead:
$subpathname = 'discover.me.txt'; // The file to discover in each extension directory. $files = array(); foreach (\Drupal::moduleHandler()->getModuleList() as $name => $module) { if (file_exists($filepath = $module->getPath() . '/' . $subpathname)) { $files[$name] = $filepath; } }
-
hook_system_theme_info() has been removed.
Additional (test) themes provided by (test) modules are discovered natively now.
-
(8.x-only)
SystemListing
andSystemListingInfo
have been removed. -
The file
example.settings.local.php
has been updated to explain how adding$settings['extension_discovery_scan_tests'] = TRUE;
to the settings array will allow the discovery of test modules. Note: without this setting, test modules are no longer discoverable by default.