Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

drupal_system_listing(), Drupal\Core\SystemListing, and Drupal\Core\SystemListingInfo have been replaced with a highly performance optimized Drupal\Core\Extension\ExtensionDiscovery.

  1. All Drupal extension types (profiles, modules, themes, theme engines) have to supply an .info.yml file in order to be discovered.

    1. Each .info.yml file must specify at least the 'type', 'core', and 'name' properties.
    2. The 'type' value for theme engines is theme_engine.
    3. 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
    
  2. drupal_system_listing() has been replaced with Drupal\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();
    
  3. 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;
      }
    }
    
  4. hook_system_theme_info() has been removed.

    Additional (test) themes provided by (test) modules are discovered natively now.

  5. (8.x-only) SystemListing and SystemListingInfo have been removed.

  6. 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.
Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done