_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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.