diff --git a/core/includes/module.inc b/core/includes/module.inc index f65f0b8..84f9125 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -59,6 +59,7 @@ function system_list($type) { function system_list_reset() { drupal_static_reset('system_list'); drupal_static_reset('system_rebuild_module_data'); + \Drupal::service('module_listing')->reset(); \Drupal::cache('bootstrap')->delete('system_list'); } diff --git a/core/lib/Drupal/Core/Extension/ExtensionList.php b/core/lib/Drupal/Core/Extension/ExtensionList.php index 8b3b47f..2e5aeae 100644 --- a/core/lib/Drupal/Core/Extension/ExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ExtensionList.php @@ -56,6 +56,13 @@ class ExtensionList { protected $moduleHandler; /** + * The static cached extensions. + * + * @var \Drupal\Core\Extension\Extension[] + */ + protected $extensions; + + /** * Constructs a new ExtensionList instance. * * @param string $root @@ -77,6 +84,20 @@ public function __construct($root, $type, StateInterface $state, InfoParserInter $this->moduleHandler = $module_handler; } + public function reset() { + $this->extensions = NULL; + $this->state->delete($this->getStateKey()); + } + + /** + * Returns the used state key. + * + * @return string + */ + protected function getStateKey() { + return 'core.extension_listing.' . $this->type; + } + /** * Returns the human readable name of the extension. * @@ -95,6 +116,19 @@ public function getName($name) { } /** + * Returns a single extension. + * + * @param string $name + * The extension name. + * + * @return \Drupal\Core\Extension\Extension + */ + public function getExtension($name) { + $extensions = $this->listExtensions(); + return $extensions[$name]; + } + + /** * Returns all available extensions. * * @return \Drupal\Core\Extension\Extension[] @@ -103,11 +137,11 @@ public function listExtensions() { if (isset($this->extensions)) { return $this->extensions; } - if ($extensions = $this->state->get('core.extension_listing.' . $this->type)) { + if ($extensions = $this->state->get($this->getStateKey())) { return $extensions; } $extensions = $this->doListExtensions(); - $this->state->get('core.extension_listing.' . $this->type); + $this->state->get($this->getStateKey()); $this->extensions = $extensions; return $this->extensions; } diff --git a/core/modules/book/src/Tests/BookUninstallTest.php b/core/modules/book/src/Tests/BookUninstallTest.php index 317a16a..ab7e065 100644 --- a/core/modules/book/src/Tests/BookUninstallTest.php +++ b/core/modules/book/src/Tests/BookUninstallTest.php @@ -44,7 +44,8 @@ protected function setUp() { */ public function testBookUninstall() { // No nodes exist. - $module_data = _system_rebuild_module_data(); + \Drupal::service('module_listing')->reset(); + $module_data = \Drupal::service('module_listing')->listExtensions(); $this->assertFalse(isset($module_data['book']->info['required']), 'The book module is not required.'); $content_type = NodeType::create(array( @@ -62,7 +63,8 @@ public function testBookUninstall() { $node->save(); // One node in a book but not of type book. - $module_data = _system_rebuild_module_data(); + \Drupal::service('module_listing')->reset(); + $module_data = \Drupal::service('module_listing')->listExtensions(); $this->assertTrue($module_data['book']->info['required'], 'The book module is required.'); $this->assertEqual($module_data['book']->info['explanation'], t('To uninstall Book, delete all content that is part of a book.')); @@ -72,26 +74,30 @@ public function testBookUninstall() { // Two nodes, one in a book but not of type book and one book node (which is // not in a book). - $module_data = _system_rebuild_module_data(); + \Drupal::service('module_listing')->reset(); + $module_data = \Drupal::service('module_listing')->listExtensions(); $this->assertTrue($module_data['book']->info['required'], 'The book module is required.'); $this->assertEqual($module_data['book']->info['explanation'], t('To uninstall Book, delete all content that is part of a book.')); $node->delete(); // One node of type book but not actually part of a book. - $module_data = _system_rebuild_module_data(); + \Drupal::service('module_listing')->reset(); + $module_data = \Drupal::service('module_listing')->listExtensions(); $this->assertTrue($module_data['book']->info['required'], 'The book module is required.'); $this->assertEqual($module_data['book']->info['explanation'], t('To uninstall Book, delete all content that has the Book content type.')); $book_node->delete(); // No nodes exist therefore the book module is not required. - $module_data = _system_rebuild_module_data(); + \Drupal::service('module_listing')->reset(); + $module_data = \Drupal::service('module_listing')->listExtensions(); $this->assertFalse(isset($module_data['book']->info['required']), 'The book module is not required.'); $node = Node::create(array('type' => $content_type->id())); $node->save(); // One node exists but is not part of a book therefore the book module is // not required. - $module_data = _system_rebuild_module_data(); + \Drupal::service('module_listing')->reset(); + $module_data = \Drupal::service('module_listing')->listExtensions(); $this->assertFalse(isset($module_data['book']->info['required']), 'The book module is not required.'); // Uninstall the Book module and check the node type is deleted. diff --git a/core/modules/filter/src/Tests/FilterAPITest.php b/core/modules/filter/src/Tests/FilterAPITest.php index 49b99d2..0386e7d 100644 --- a/core/modules/filter/src/Tests/FilterAPITest.php +++ b/core/modules/filter/src/Tests/FilterAPITest.php @@ -424,7 +424,8 @@ public function testDependencyRemoval() { ]; $filter_format->setFilterConfig('filter_test_restrict_tags_and_attributes', $filter_config)->save(); - $module_data = _system_rebuild_module_data(); + \Drupal::service('module_listing')->reset(); + $module_data = \Drupal::service('module_listing')->listExtensions(); $this->assertTrue($module_data['filter_test']->info['required'], 'The filter_test module is required.'); $this->assertEqual($module_data['filter_test']->info['explanation'], SafeMarkup::format('Provides a filter plugin that is in use in the following filter formats: %formats', array('%formats' => $filter_format->label()))); @@ -443,7 +444,8 @@ public function testDependencyRemoval() { drupal_static_reset('filter_formats'); \Drupal::entityManager()->getStorage('filter_format')->resetCache(); - $module_data = _system_rebuild_module_data(); + \Drupal::service('module_listing')->reset(); + $module_data = \Drupal::service('module_listing')->listExtensions(); $this->assertFalse(isset($module_data['filter_test']->info['required']), 'The filter_test module is required.'); // Verify that a dependency exists on the module that provides the filter diff --git a/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php b/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php index d2d6fed..edaf2a0 100644 --- a/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php +++ b/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php @@ -115,6 +115,7 @@ function testDependencyResolution() { // Nothing should be installed. \Drupal::state()->set('module_test.dependency', 'missing dependency'); drupal_static_reset('system_rebuild_module_data'); + \Drupal::service('module_listing')->reset(); try { $result = $this->moduleInstaller()->install(array('color')); @@ -130,6 +131,7 @@ function testDependencyResolution() { // Color module depends on Config. Config depends on Help module. \Drupal::state()->set('module_test.dependency', 'dependency'); drupal_static_reset('system_rebuild_module_data'); + \Drupal::service('module_listing')->reset(); $result = $this->moduleInstaller()->install(array('color')); $this->assertTrue($result, 'ModuleHandler::install() returns the correct value.'); @@ -162,6 +164,7 @@ function testDependencyResolution() { // sure that Drupal\Core\Extension\ModuleHandler::install() still works. \Drupal::state()->set('module_test.dependency', 'version dependency'); drupal_static_reset('system_rebuild_module_data'); + \Drupal::service('module_listing')->reset(); $result = $this->moduleInstaller()->install(array('color')); $this->assertTrue($result, 'ModuleHandler::install() returns the correct value.');