From 4c893b7fd0c97628e1f2b4f9e2f054bc3987d905 Mon Sep 17 00:00:00 2001 From: Alexander Varwijk Date: Mon, 28 Aug 2023 17:23:53 +0200 Subject: [PATCH] Fix view name for groups search We can't just fix the change in `social_search_update_11403` because we would leave sites that had already executed the update in an indeterminate state. There's two scenarios: 1) The update has already run. In this case the change for the groups view hasn't happened due to the type, the new update hook will be executed and now all views are correct. 2) The update hook hasn't run already. In this case we do the correct 2 views (that sites from scenario 1 don't need help changing) in 11403 and we fix groups in 11404. --- .../social_search/social_search.install | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/modules/social_features/social_search/social_search.install b/modules/social_features/social_search/social_search.install index 2aea01bc7b8..51bc32dd9d5 100644 --- a/modules/social_features/social_search/social_search.install +++ b/modules/social_features/social_search/social_search.install @@ -307,7 +307,6 @@ function social_search_update_11403() : void { $views = [ "views.view.search_all", "views.view.search_content", - "views.view.search_group", ]; foreach ($views as $view) { @@ -323,3 +322,33 @@ function social_search_update_11403() : void { $config->save(TRUE); } } + +/** + * Revert search_api_language filter name/id change for groups view. + */ +function social_search_update_11404() : void { + // There was a typo in the view name of social_search_update_11403 which + // caused the groups view not to be updated, so we must do it again here. + $views = [ + "views.view.search_groups", + ]; + + foreach ($views as $view) { + $config = \Drupal::configFactory()->getEditable($view); + $display = $config->get("display"); + + $filter = $display['default']['display_options']['filters']['language_with_fallback']; + $filter['id'] = "search_api_language"; + $display['default']['display_options']['filters']["search_api_language"] = $filter; + unset($display['default']['display_options']['filters']['language_with_fallback']); + + $config->set('display', $display); + $config->save(TRUE); + } + + // Clean up the config created in our erroneous version of 11403. + $incorrect_view = \Drupal::configFactory()->getEditable("views.view.search_group"); + if (!$incorrect_view->isNew()) { + $incorrect_view->delete(); + } +}