diff --git a/core/includes/module.inc b/core/includes/module.inc index 928abc9..fad9761 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -107,9 +107,7 @@ function module_list($refresh = FALSE, $bootstrap_refresh = FALSE, $sort = FALSE $list = system_list('bootstrap'); } else { - // Not using drupal_map_assoc() here as that requires common.inc. - $list = array_keys(system_list('module_enabled')); - $list = (!empty($list) ? array_combine($list, $list) : array()); + $list = system_list('module_enabled'); } } } @@ -134,9 +132,9 @@ function module_list($refresh = FALSE, $bootstrap_refresh = FALSE, $sort = FALSE * * @return * An associative array of modules or themes, keyed by name. For $type - * 'bootstrap', the array values equal the keys. For $type 'module_enabled' - * or 'theme', the array values are objects representing the respective - * database row, with the 'info' property already unserialized. + * 'bootstrap' and 'module_enabled', the array values equal the keys. + * For $type 'theme', the array values are objects representing the + * respective database row, with the 'info' property already unserialized. * * @see module_list() * @see list_themes() @@ -187,13 +185,13 @@ function system_list($type) { // consistent with the one used in module_implements(). $result = db_query("SELECT * FROM {system} WHERE type = 'theme' OR (type = 'module' AND status = 1) ORDER BY weight ASC, name ASC"); foreach ($result as $record) { - $record->info = unserialize($record->info); // Build a list of all enabled modules. if ($record->type == 'module') { - $lists['module_enabled'][$record->name] = $record; + $lists['module_enabled'][$record->name] = $record->name; } // Build a list of themes. if ($record->type == 'theme') { + $record->info = unserialize($record->info); $lists['theme'][$record->name] = $record; } // Build a list of filenames so drupal_get_filename can use it. @@ -246,6 +244,7 @@ function system_list_reset() { drupal_static_reset('system_rebuild_module_data'); drupal_static_reset('list_themes'); cache('bootstrap')->deleteMultiple(array('bootstrap_modules', 'system_list')); + cache()->delete('system_info'); } /** diff --git a/core/lib/Drupal/Core/Utility/ModuleInfo.php b/core/lib/Drupal/Core/Utility/ModuleInfo.php new file mode 100644 index 0000000..e5391f2 --- /dev/null +++ b/core/lib/Drupal/Core/Utility/ModuleInfo.php @@ -0,0 +1,41 @@ +info)) { + $this->info = system_get_info('module'); + } + foreach ($this->info as $module => $info) { + if (isset($info[$offset])) { + $data[$module] = $info[$offset]; + } + } + $this->storage[$offset] = $data; + $this->persist($offset); + return $data; + } +} diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 73236f7..03adb29 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1,5 +1,8 @@ $info) { - if (!empty($info['stylesheets'])) { - foreach ($info['stylesheets'] as $media => $stylesheets) { - foreach ($stylesheets as $stylesheet) { - drupal_add_css($stylesheet, array('every_page' => TRUE, 'media' => $media)); - } + foreach (system_get_module_info('stylesheets') as $module => $value) { + foreach ($value as $media => $stylesheets) { + foreach ($stylesheets as $stylesheet) { + drupal_add_css($stylesheet, array('every_page' => TRUE, 'media' => $media)); } } - if (!empty($info['scripts'])) { - foreach ($info['scripts'] as $script) { - drupal_add_js($script, array('every_page' => TRUE)); - } + } + foreach (system_get_module_info('scripts') as $module => $scripts) { + foreach ($scripts as $script) { + drupal_add_js($script, array('every_page' => TRUE)); } } } @@ -2423,12 +2424,17 @@ function system_update_files_database(&$files, $type) { function system_get_info($type, $name = NULL) { $info = array(); if ($type == 'module') { - $type = 'module_enabled'; + $result = db_query('SELECT name, info FROM {system} WHERE type = :type AND status = 1', array(':type' => 'module')); + foreach ($result as $record) { + $info[$record->name] = unserialize($record->info); + } } - $list = system_list($type); - foreach ($list as $shortname => $item) { - if (!empty($item->status)) { - $info[$shortname] = $item->info; + else { + $list = system_list($type); + foreach ($list as $shortname => $item) { + if (!empty($item->status)) { + $info[$shortname] = $item->info; + } } } if (isset($name)) { @@ -2438,6 +2444,28 @@ function system_get_info($type, $name = NULL) { } /** + * Return .info data for modules. + * + * @param $property + * The .info property to retrieve. + * + * @return + * An array keyed by module name, with the .info file property as values. + * Only modules with the property specified in their .info file will be + * returned. + * + * @see Drupal\Core\Utility\ModuleInfo + */ +function system_get_module_info($property) { + static $info; + if (!isset($info)) { + $info = new ModuleInfo('system_info', 'cache'); + } + + return $info[$property]; +} + +/** * Helper function to scan and collect module .info data. * * @return