_system_rebuild_module_data

_system_rebuild_module_data()

Helper function to scan and collect module .info.yml data.

Return value

\Drupal\Core\Extension\Extension[] An associative array of module information.

File

core/modules/system/system.module, line 958
Configuration system that lets administrators modify the workings of the site.

Code

function _system_rebuild_module_data() {
  $listing = new ExtensionDiscovery(\Drupal::root());

  // Find installation profiles. This needs to happen before performing a
  // module scan as the module scan requires knowing what the active profile is.
  // @todo Remove as part of https://www.drupal.org/node/2186491.
  $profiles = $listing->scan('profile');
  $profile = drupal_get_profile();
  if ($profile && isset($profiles[$profile])) {
    // Prime the drupal_get_filename() static cache with the profile info file
    // location so we can use drupal_get_path() on the active profile during
    // the module scan.
    // @todo Remove as part of https://www.drupal.org/node/2186491.
    drupal_get_filename('profile', $profile, $profiles[$profile]->getPathname());
  }

  // Find modules.
  $modules = $listing->scan('module');
  // Include the installation profile in modules that are loaded.
  if ($profile) {
    $modules[$profile] = $profiles[$profile];
    // Installation profile hooks are always executed last.
    $modules[$profile]->weight = 1000;
  }

  // Set defaults for module info.
  $defaults = array(
    'dependencies' => array(),
    'description' => '',
    'package' => 'Other',
    'version' => NULL,
    'php' => DRUPAL_MINIMUM_PHP,
  );

  // Read info files for each module.
  foreach ($modules as $key => $module) {
    // Look for the info file.
    $module->info = \Drupal::service('info_parser')->parse($module->getPathname());

    // Add the info file modification time, so it becomes available for
    // contributed modules to use for ordering module lists.
    $module->info['mtime'] = $module->getMTime();

    // Merge in defaults and save.
    $modules[$key]->info = $module->info + $defaults;

    // Installation profiles are hidden by default, unless explicitly specified
    // otherwise in the .info.yml file.
    if ($key == $profile && !isset($modules[$key]->info['hidden'])) {
      $modules[$key]->info['hidden'] = TRUE;
    }

    // Invoke hook_system_info_alter() to give installed modules a chance to
    // modify the data in the .info.yml files if necessary.
    // @todo Remove $type argument, obsolete with $module->getType().
    $type = 'module';
    \Drupal::moduleHandler()->alter('system_info', $modules[$key]->info, $modules[$key], $type);
  }

  // It is possible that a module was marked as required by
  // hook_system_info_alter() and modules that it depends on are not required.
  foreach ($modules as $module) {
    _system_rebuild_module_data_ensure_required($module, $modules);
  }


  if ($profile && isset($modules[$profile])) {
    // The installation profile is required, if it's a valid module.
    $modules[$profile]->info['required'] = TRUE;
    // Add a default distribution name if the profile did not provide one.
    // @see install_profile_info()
    // @see drupal_install_profile_distribution_name()
    if (!isset($modules[$profile]->info['distribution']['name'])) {
      $modules[$profile]->info['distribution']['name'] = 'Drupal';
    }
  }

  return $modules;
}
doc_Drupal
2016-10-29 09:57:19
Comments
Leave a Comment

Please login to continue.