diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index 7d72aa44bc..def87f53a1 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -161,6 +161,7 @@ function simpletest_run_tests($test_list) { batch_set($batch); \Drupal::moduleHandler()->invokeAll('test_group_started'); + system_trigger_deprecated_hook_error('test_group_started'); return $test_id; } @@ -421,6 +422,7 @@ function _simpletest_batch_operation($test_list_init, $test_id, &$context) { $test = new $test_class($test_id); $test->run(); \Drupal::moduleHandler()->invokeAll('test_finished', [$test->results]); + system_trigger_deprecated_hook_error('test_finished'); $test_results[$test_class] = $test->results; } $size = count($test_list); @@ -483,6 +485,7 @@ function _simpletest_batch_finished($success, $results, $operations, $elapsed) { drupal_set_message(t('Use the Clean environment button to clean-up temporary files and tables.'), 'warning'); } \Drupal::moduleHandler()->invokeAll('test_group_finished'); + system_trigger_deprecated_hook_error('test_group_finished'); } /** diff --git a/core/modules/system/system.module b/core/modules/system/system.module index a1a6b715a3..cb406ea6fa 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1489,3 +1489,31 @@ function system_query_entity_reference_alter(AlterableInterface $query) { $handler = $query->getMetadata('entity_reference_selection_handler'); $handler->entityQueryAlter($query); } + + +/** + * Helper function to trigger errors for deprecated hooks. + * + * Call this function with the same hook name as + * ModuleHandlerInterface::invokeAll(), and it will trigger a deprecation error + * if any enabled module implements that hook. + * + * @param string $deprecated_hook + * The name of the deprecated hook, such as 'test_finished'. + */ +function system_trigger_deprecated_hook_error($deprecated_hook) { + $implements_deprecated = []; + + $module_handler = \Drupal::moduleHandler(); + $modules = array_keys($module_handler->getModuleList()); + + foreach ($modules as $module) { + if ($module_handler->implementsHook($module, $deprecated_hook)) { + $implements_deprecated[] = $module; + } + } + + if (!empty($implements_deprecated)) { + @trigger_error('The following modules implement the deprecated hook ' . $deprecated_hook . ': ' . implode(', ', $implements_deprecated), E_USER_DEPRECATED); + } +}