Issue #2181811 by alexpott: System info can become inconsistent if hook_system_info_alter() makes a module required.
parent
733eed41fc
commit
8bc36db189
|
@ -29,6 +29,9 @@ class InfoAlterTest extends WebTestBase {
|
||||||
* return freshly altered info.
|
* return freshly altered info.
|
||||||
*/
|
*/
|
||||||
function testSystemInfoAlter() {
|
function testSystemInfoAlter() {
|
||||||
|
\Drupal::state()->set('module_test.hook_system_info_alter', TRUE);
|
||||||
|
$info = system_rebuild_module_data();
|
||||||
|
$this->assertFalse(isset($info['node']->info['required']), 'Before the module_test is installed the node module is not required.');
|
||||||
// Enable seven and the test module.
|
// Enable seven and the test module.
|
||||||
theme_enable(array('seven'));
|
theme_enable(array('seven'));
|
||||||
\Drupal::moduleHandler()->install(array('module_test'), FALSE);
|
\Drupal::moduleHandler()->install(array('module_test'), FALSE);
|
||||||
|
@ -44,5 +47,9 @@ class InfoAlterTest extends WebTestBase {
|
||||||
$this->assertTrue(isset($info['regions']['test_region']), 'Altered theme info was returned by system_list().');
|
$this->assertTrue(isset($info['regions']['test_region']), 'Altered theme info was returned by system_list().');
|
||||||
$list_themes = list_themes();
|
$list_themes = list_themes();
|
||||||
$this->assertTrue(isset($list_themes['seven']->info['regions']['test_region']), 'Altered theme info was returned by list_themes().');
|
$this->assertTrue(isset($list_themes['seven']->info['regions']['test_region']), 'Altered theme info was returned by list_themes().');
|
||||||
|
system_list_reset();
|
||||||
|
$info = system_rebuild_module_data();
|
||||||
|
$this->assertTrue($info['node']->info['required'], 'After the module_test is installed the node module is required.');
|
||||||
|
\Drupal::state()->set('module_test.hook_system_info_alter', FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2434,6 +2434,13 @@ function _system_rebuild_module_data() {
|
||||||
drupal_alter('system_info', $modules[$key]->info, $modules[$key], $type);
|
drupal_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 (isset($modules[$profile])) {
|
if (isset($modules[$profile])) {
|
||||||
// The installation profile is required, if it's a valid module.
|
// The installation profile is required, if it's a valid module.
|
||||||
$modules[$profile]->info['required'] = TRUE;
|
$modules[$profile]->info['required'] = TRUE;
|
||||||
|
@ -2447,6 +2454,27 @@ function _system_rebuild_module_data() {
|
||||||
return $modules;
|
return $modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensures that dependencies of required modules are also required.
|
||||||
|
*
|
||||||
|
* @param \stdClass $module
|
||||||
|
* The module info.
|
||||||
|
* @param array $modules
|
||||||
|
* The array of all module info.
|
||||||
|
*/
|
||||||
|
function _system_rebuild_module_data_ensure_required($module, &$modules) {
|
||||||
|
if (!empty($module->info['required'])) {
|
||||||
|
foreach ($module->info['dependencies'] as $dependant) {
|
||||||
|
if (!isset($modules[$dependant]->info['required'])) {
|
||||||
|
$modules[$dependant]->info['required'] = TRUE;
|
||||||
|
$modules[$dependant]->info['explanation'] = t('Dependency of required module @module', array('@module' => $module->name));
|
||||||
|
// Ensure any dependencies it has are required.
|
||||||
|
_system_rebuild_module_data_ensure_required($modules[$dependant], $modules);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rebuild, save, and return data about all currently available modules.
|
* Rebuild, save, and return data about all currently available modules.
|
||||||
*
|
*
|
||||||
|
|
|
@ -5,3 +5,8 @@ package: Testing
|
||||||
version: VERSION
|
version: VERSION
|
||||||
core: 8.x
|
core: 8.x
|
||||||
hidden: true
|
hidden: true
|
||||||
|
# Depends on the Node module to test making a module required using
|
||||||
|
# hook_system_info_alter() and ensuring that its dependencies also become
|
||||||
|
# required.
|
||||||
|
dependencies:
|
||||||
|
- node
|
||||||
|
|
|
@ -52,6 +52,10 @@ function module_test_system_info_alter(&$info, $file, $type) {
|
||||||
if ($file->name == 'seven' && $type == 'theme') {
|
if ($file->name == 'seven' && $type == 'theme') {
|
||||||
$info['regions']['test_region'] = t('Test region');
|
$info['regions']['test_region'] = t('Test region');
|
||||||
}
|
}
|
||||||
|
if ($file->name == 'module_test' && \Drupal::state()->get('module_test.hook_system_info_alter')) {
|
||||||
|
$info['required'] = TRUE;
|
||||||
|
$info['explanation'] = 'Testing hook_system_info_alter()';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue