diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php index 7598c8a284..f04eeca72a 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -439,7 +439,12 @@ public function invokeAllDeprecated($hook, array $args = array()) { private function triggerDeprecationError($hook) { $modules = array_keys($this->getImplementationInfo($hook)); if (!empty($modules)) { - @trigger_error('The following modules implement the deprecated hook hook_' . $hook . '(): ' . implode(', ', $modules), E_USER_DEPRECATED); + $message = 'The deprecated hook hook_' . $hook . '() is implemented in these functions: '; + $hooks = []; + foreach ($modules as $module) { + $hooks[] = $module . '_' . $hook . '()'; + } + @trigger_error($message . implode(', ', $hooks), E_USER_DEPRECATED); } } @@ -551,7 +556,7 @@ public function alterDeprecated($type, &$data, &$context1 = NULL, &$context2 = N $type = array_shift($extra_types); } if (!empty($this->alterFunctions[$cid])) { - $message = 'The deprecated alter hook hook_' . $type . '_alter() is implemented: ' . implode(', ', $this->alterFunctions[$cid]); + $message = 'The deprecated alter hook hook_' . $type . '_alter() is implemented in these functions: ' . implode(', ', $this->alterFunctions[$cid]); @trigger_error($message, E_USER_DEPRECATED); } } diff --git a/core/modules/system/tests/modules/deprecation_test/deprecation_test.module b/core/modules/system/tests/modules/deprecation_test/deprecation_test.module deleted file mode 100644 index 64bbe166dc..0000000000 --- a/core/modules/system/tests/modules/deprecation_test/deprecation_test.module +++ /dev/null @@ -1,14 +0,0 @@ -container->get('module_handler'); - $data = ['some', 'data']; - $module_handler->alterDeprecated('deprecate', $data); - $this->assertContains('altered!', $data); - } - - /** - * @covers ::alterDeprecated - * @expectedDeprecation The following modules implement the deprecated hook hook_deprecate(): deprecation_test - */ - public function testInvokeDeprecated() { - /* @var $module_handler \Drupal\Core\Extension\ModuleHandler */ - $module_handler = $this->container->get('module_handler'); - $this->assertEquals( - 'hooked!', - $module_handler->invokeDeprecated('deprecation_test', 'deprecate') - ); - } - - /** - * @covers ::alterDeprecated - * @expectedDeprecation The following modules implement the deprecated hook hook_deprecate(): deprecation_test - */ - public function testInvokeAllDeprecated() { - /* @var $module_handler \Drupal\Core\Extension\ModuleHandler */ - $module_handler = $this->container->get('module_handler'); - // The invokeAll() method returns an array of values from various - // implementations, so we have to find our known value in the result array. - $this->assertContains('hooked!', $module_handler->invokeAllDeprecated('deprecate'), true); - } - -} diff --git a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerDeprecatedTest.php b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerDeprecatedTest.php new file mode 100644 index 0000000000..1aa381fd09 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerDeprecatedTest.php @@ -0,0 +1,84 @@ +cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); + + $this->moduleHandler = new ModuleHandler($this->root, [], $this->cacheBackend); + $this->moduleHandler->addModule('module_handler_test_deprecated', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_deprecated'); + $this->moduleHandler->load('module_handler_test_deprecated'); + } + + /** + * @covers ::alterDeprecated + * @expectedDeprecation The deprecated alter hook hook_deprecate_alter() is implemented in these functions: module_handler_test_deprecated_deprecate_alter + */ + public function testAlterDeprecated() { + $data = ['some', 'data']; + $this->moduleHandler->alterDeprecated('deprecate', $data); + $this->assertContains('altered', $data); + } + + /** + * @covers ::invokeDeprecated + * @expectedDeprecation The deprecated hook hook_deprecate() is implemented in these functions: module_handler_test_deprecated_deprecate() + */ + public function testInvokeDeprecated() { + $this->assertEquals( + 'hooked', + $this->moduleHandler->invokeDeprecated('module_handler_test_deprecated', 'deprecate') + ); + } + + /** + * @covers ::invokeAllDeprecated + * @expectedDeprecation The deprecated hook hook_deprecate() is implemented in these functions: module_handler_test_deprecated_deprecate() + */ + public function testInvokeAllDeprecated() { + // The invokeAll() method returns an array of values from various + // implementations, so we have to find our known value in the result array. + $this->assertContains( + 'hooked', + $this->moduleHandler->invokeAllDeprecated('deprecate') + ); + } + +} diff --git a/core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_deprecated/module_handler_test_deprecated.info.yml b/core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_deprecated/module_handler_test_deprecated.info.yml new file mode 100644 index 0000000000..b6dd0bf5fe --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_deprecated/module_handler_test_deprecated.info.yml @@ -0,0 +1,7 @@ +name: module handler test deprecated module +type: module +description: 'Test module enabled in ModuleHandlerDeprecatedTest.' +package: Testing +version: VERSION +core: 8.x + diff --git a/core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_deprecated/module_handler_test_deprecated.module b/core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_deprecated/module_handler_test_deprecated.module new file mode 100644 index 0000000000..71cffa5480 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_deprecated/module_handler_test_deprecated.module @@ -0,0 +1,14 @@ +