From fd565007ee7fde9eb13f080bdef305d4224025c7 Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Mon, 26 Apr 2021 15:13:51 +0100 Subject: [PATCH] Issue #3209139 by guilhermevp, andypost, jhodgdon: Create helper function for help_topics_modules_installed() --- core/modules/help_topics/help_topics.module | 53 ++++++++++++--------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/core/modules/help_topics/help_topics.module b/core/modules/help_topics/help_topics.module index 935b6ac7b855..92e23e050762 100644 --- a/core/modules/help_topics/help_topics.module +++ b/core/modules/help_topics/help_topics.module @@ -60,45 +60,52 @@ function help_topics_theme() { * Implements hook_modules_uninstalled(). */ function help_topics_modules_uninstalled(array $modules) { - // Early return if search is not installed or if we're uninstalling this - // module. - if (!\Drupal::hasService('plugin.manager.search') || - in_array('help_topics', $modules)) { - return; - } - $search_plugin_manager = \Drupal::service('plugin.manager.search'); - if ($search_plugin_manager->hasDefinition('help_search')) { - // Ensure that topics for extensions that have been uninstalled are removed - // and that the index state variable is updated. - $help_search = $search_plugin_manager->createInstance('help_search'); - $help_search->updateTopicList(); - $help_search->updateIndexState(); - } + _help_topics_search_update($modules); } /** * Implements hook_themes_uninstalled(). */ function help_topics_themes_uninstalled(array $themes) { - // Use the same code as module uninstall to ensure that theme help is removed - // when a theme is uninstalled. - help_topics_modules_uninstalled([]); + _help_topics_search_update(); } /** * Implements hook_modules_installed(). */ function help_topics_modules_installed(array $modules, $is_syncing) { - // Use the same code as module uninstall to ensure that index state is - // updated when a module is installed. - help_topics_modules_uninstalled([]); + _help_topics_search_update(); } /** * Implements hook_themes_installed(). */ function help_topics_themes_installed(array $themes) { - // Use the same code as module uninstall to ensure that index state is - // updated when a theme is installed. - help_topics_modules_uninstalled([]); + _help_topics_search_update(); +} + +/** + * Ensure that search is updated when extensions are installed or uninstalled. + * + * @param string[] $extensions + * (optional) If modules are being uninstalled, the names of the modules + * being uninstalled. For themes being installed/uninstalled, or modules + * being installed, omit this parameter. + */ +function _help_topics_search_update(array $extensions = []): void { + // Early return if search is not installed or if we're uninstalling this + // module. + if (!\Drupal::hasService('plugin.manager.search') || + in_array('help_topics', $extensions)) { + return; + } + + $search_plugin_manager = \Drupal::service('plugin.manager.search'); + if ($search_plugin_manager->hasDefinition('help_search')) { + // Ensure that topics for extensions that have been uninstalled are removed + // and that the index state variable is updated. + $help_search = $search_plugin_manager->createInstance('help_search'); + $help_search->updateTopicList(); + $help_search->updateIndexState(); + } } -- GitLab