From 3951fa4de90ad3b1038eb96030a734b71b1eba4c Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Thu, 8 Feb 2024 23:22:34 +0000
Subject: [PATCH] Issue #3405660 by smustgrave, quietone, Wim Leers, larowlan,
 lauriii: Remove tour from themes

---
 .../tour/css/theme/claro-tour.theme.css}      |  0
 .../tour/css/theme/claro-tour.theme.pcss.css} |  0
 .../tour/css/theme/stable9-tour.module.css}   |  0
 .../js => modules/tour/js/theme}/tour.js      |  0
 core/modules/tour/tour.libraries.yml          | 14 +++++++++++++
 core/modules/tour/tour.module                 | 20 +++++++++++++++++++
 ...solvedLibraryDefinitionsFilesMatchTest.php |  8 ++++++--
 .../Core/Theme/Stable9LibraryOverrideTest.php |  3 +++
 .../Theme/StableLibraryOverrideTestBase.php   |  7 ++++++-
 core/themes/claro/claro.info.yml              |  2 --
 core/themes/claro/claro.libraries.yml         |  6 ------
 .../olivero/css/components/site-header.css    |  2 +-
 .../css/components/site-header.pcss.css       |  2 +-
 core/themes/stable9/stable9.info.yml          |  9 ---------
 core/themes/stable9/stable9.libraries.yml     |  5 -----
 15 files changed, 51 insertions(+), 27 deletions(-)
 rename core/{themes/claro/css/theme/tour.theme.css => modules/tour/css/theme/claro-tour.theme.css} (100%)
 rename core/{themes/claro/css/theme/tour.theme.pcss.css => modules/tour/css/theme/claro-tour.theme.pcss.css} (100%)
 rename core/{themes/stable9/css/tour/tour.module.css => modules/tour/css/theme/stable9-tour.module.css} (100%)
 rename core/{themes/stable9/js => modules/tour/js/theme}/tour.js (100%)

diff --git a/core/themes/claro/css/theme/tour.theme.css b/core/modules/tour/css/theme/claro-tour.theme.css
similarity index 100%
rename from core/themes/claro/css/theme/tour.theme.css
rename to core/modules/tour/css/theme/claro-tour.theme.css
diff --git a/core/themes/claro/css/theme/tour.theme.pcss.css b/core/modules/tour/css/theme/claro-tour.theme.pcss.css
similarity index 100%
rename from core/themes/claro/css/theme/tour.theme.pcss.css
rename to core/modules/tour/css/theme/claro-tour.theme.pcss.css
diff --git a/core/themes/stable9/css/tour/tour.module.css b/core/modules/tour/css/theme/stable9-tour.module.css
similarity index 100%
rename from core/themes/stable9/css/tour/tour.module.css
rename to core/modules/tour/css/theme/stable9-tour.module.css
diff --git a/core/themes/stable9/js/tour.js b/core/modules/tour/js/theme/tour.js
similarity index 100%
rename from core/themes/stable9/js/tour.js
rename to core/modules/tour/js/theme/tour.js
diff --git a/core/modules/tour/tour.libraries.yml b/core/modules/tour/tour.libraries.yml
index 52cbc50573d8..19c0d3a39ca3 100644
--- a/core/modules/tour/tour.libraries.yml
+++ b/core/modules/tour/tour.libraries.yml
@@ -16,3 +16,17 @@ tour-styling:
   css:
     component:
       css/tour.module.css: { media: screen }
+
+tour-claro-styling:
+  version: VERSION
+  css:
+    theme:
+      css/theme/claro-tour.theme.css: {}
+
+tour-stable9-styling:
+  version: VERSION
+  js:
+    js/theme/tour.js: {}
+  css:
+    theme:
+      css/theme/stable9-tour.module.css: {}
diff --git a/core/modules/tour/tour.module b/core/modules/tour/tour.module
index da432ef9ed7f..bd05f7311c73 100644
--- a/core/modules/tour/tour.module
+++ b/core/modules/tour/tour.module
@@ -115,3 +115,23 @@ function tour_tour_insert($entity) {
 function tour_tour_update($entity) {
   \Drupal::service('plugin.manager.tour.tip')->clearCachedDefinitions();
 }
+
+/**
+ * Implements hook_library_info_alter().
+ */
+function tour_library_info_alter(&$libraries, $extension) {
+  if ($extension === 'tour') {
+    $theme = \Drupal::service('theme.manager')->getActiveTheme()->getName();
+    $base_theme = FALSE;
+    if ($theme && !\Drupal::service('theme_handler')->listInfo()[$theme]) {
+      $base_theme = \Drupal::service('theme_handler')->listInfo()[$theme]->base_theme;
+    }
+    if (in_array('claro', [$theme, $base_theme])) {
+      $libraries['tour']['dependencies'][] = 'tour/tour-claro-styling';
+    }
+    elseif (in_array('stable9', [$theme, $base_theme])) {
+      $libraries['tour']['dependencies'][] = 'tour/tour-stable9-styling';
+    }
+  }
+
+}
diff --git a/core/tests/Drupal/KernelTests/Core/Asset/ResolvedLibraryDefinitionsFilesMatchTest.php b/core/tests/Drupal/KernelTests/Core/Asset/ResolvedLibraryDefinitionsFilesMatchTest.php
index 5ba0c7bb4d8f..e31900a27efa 100644
--- a/core/tests/Drupal/KernelTests/Core/Asset/ResolvedLibraryDefinitionsFilesMatchTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Asset/ResolvedLibraryDefinitionsFilesMatchTest.php
@@ -207,7 +207,10 @@ protected function getAllLibraries() {
     $extensions = $modules;
     $module_list = array_keys($modules);
     sort($module_list);
-    $this->assertEquals($this->allModules, $module_list, 'All core modules are installed.');
+    // Remove deprecated module Tour.
+    $module_list = array_diff($module_list, ['tour']);
+    $all_modules = array_diff($this->allModules, ['tour']);
+    $this->assertEquals($all_modules, $module_list, 'All core modules are installed.');
 
     $themes = $this->themeHandler->listInfo();
     $extensions += $themes;
@@ -216,7 +219,8 @@ protected function getAllLibraries() {
     $this->assertEquals($this->allThemes, $theme_list, 'All core themes are installed.');
 
     $libraries['core'] = $this->libraryDiscovery->getLibrariesByExtension('core');
-
+    // Remove deprecated module Tour.
+    unset($extensions['tour']);
     foreach ($extensions as $extension_name => $extension) {
       $library_file = $extension->getPath() . '/' . $extension_name . '.libraries.yml';
       if (is_file($this->root . '/' . $library_file)) {
diff --git a/core/tests/Drupal/KernelTests/Core/Theme/Stable9LibraryOverrideTest.php b/core/tests/Drupal/KernelTests/Core/Theme/Stable9LibraryOverrideTest.php
index 39ccd4038d53..20bbe21c5bf3 100644
--- a/core/tests/Drupal/KernelTests/Core/Theme/Stable9LibraryOverrideTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Theme/Stable9LibraryOverrideTest.php
@@ -26,6 +26,9 @@ class Stable9LibraryOverrideTest extends StableLibraryOverrideTestBase {
     'media/drupal.media-icon',
     'options/drupal.options-icon',
     'telephone/drupal.telephone-icon',
+    'tour/tour-styling',
+    'tour/tour-claro-styling',
+    'tour/tour-stable9-styling',
   ];
 
   /**
diff --git a/core/tests/Drupal/KernelTests/Core/Theme/StableLibraryOverrideTestBase.php b/core/tests/Drupal/KernelTests/Core/Theme/StableLibraryOverrideTestBase.php
index 6e80b20fbd52..bfe0ecfafd34 100644
--- a/core/tests/Drupal/KernelTests/Core/Theme/StableLibraryOverrideTestBase.php
+++ b/core/tests/Drupal/KernelTests/Core/Theme/StableLibraryOverrideTestBase.php
@@ -121,10 +121,15 @@ protected function getAllLibraries() {
     $modules = \Drupal::moduleHandler()->getModuleList();
     $module_list = array_keys($modules);
     sort($module_list);
-    $this->assertEquals($this->allModules, $module_list, 'All core modules are installed.');
+    // Remove deprecated module Tour.
+    $module_list = array_diff($module_list, ['tour']);
+    $all_modules = array_diff($this->allModules, ['tour']);
+    $this->assertEquals($all_modules, $module_list, 'All core modules are installed.');
 
     $libraries['core'] = $this->libraryDiscovery->getLibrariesByExtension('core');
 
+    // Remove deprecated module Tour.
+    unset($modules['tour']);
     foreach ($modules as $module_name => $module) {
       $library_file = $module->getPath() . '/' . $module_name . '.libraries.yml';
       if (is_file($this->root . '/' . $library_file)) {
diff --git a/core/themes/claro/claro.info.yml b/core/themes/claro/claro.info.yml
index 5b8fd2393527..c47d4b86e51c 100644
--- a/core/themes/claro/claro.info.yml
+++ b/core/themes/claro/claro.info.yml
@@ -128,8 +128,6 @@ libraries-extend:
     - claro/system.admin
   core/drupal.autocomplete:
     - claro/autocomplete
-  tour/tour-styling:
-    - claro/tour-styling
   shortcut/drupal.shortcut:
     - claro/drupal.shortcut
   core/drupal.ajax:
diff --git a/core/themes/claro/claro.libraries.yml b/core/themes/claro/claro.libraries.yml
index 3a16437d1ae7..bcc8788ebea2 100644
--- a/core/themes/claro/claro.libraries.yml
+++ b/core/themes/claro/claro.libraries.yml
@@ -139,12 +139,6 @@ drupal.node.preview:
     theme:
       css/components/node-preview.css: {}
 
-tour-styling:
-  version: VERSION
-  css:
-    theme:
-      css/theme/tour.theme.css: {}
-
 media-form:
   version: VERSION
   css:
diff --git a/core/themes/olivero/css/components/site-header.css b/core/themes/olivero/css/components/site-header.css
index 6dc7c5162ac3..ecbdc1ea9cc7 100644
--- a/core/themes/olivero/css/components/site-header.css
+++ b/core/themes/olivero/css/components/site-header.css
@@ -14,7 +14,7 @@
   position: relative;
   /**
    * Ensure mobile site header is always above other elements including
-   * contextual links, and Tour.
+   * contextual links.
    */
   z-index: 101;
 }
diff --git a/core/themes/olivero/css/components/site-header.pcss.css b/core/themes/olivero/css/components/site-header.pcss.css
index 1ab7251194de..ee6822646357 100644
--- a/core/themes/olivero/css/components/site-header.pcss.css
+++ b/core/themes/olivero/css/components/site-header.pcss.css
@@ -9,7 +9,7 @@
   position: relative;
   /**
    * Ensure mobile site header is always above other elements including
-   * contextual links, and Tour.
+   * contextual links.
    */
   z-index: 101;
 
diff --git a/core/themes/stable9/stable9.info.yml b/core/themes/stable9/stable9.info.yml
index fd2dd2e022fb..4c757b84feed 100644
--- a/core/themes/stable9/stable9.info.yml
+++ b/core/themes/stable9/stable9.info.yml
@@ -261,11 +261,6 @@ libraries-override:
       state:
         css/toolbar.menu.css: css/toolbar/toolbar.menu.css
 
-  tour/tour-styling:
-    css:
-      component:
-        css/tour.module.css: css/tour/tour.module.css
-
   update/drupal.update.admin:
     css:
       theme:
@@ -300,7 +295,3 @@ libraries-override:
     css:
       theme:
         css/field_ui_display_mode_table.css: css/field_ui/field_ui_display_mode_table.css
-
-libraries-extend:
-  tour/tour:
-    - stable9/tour
diff --git a/core/themes/stable9/stable9.libraries.yml b/core/themes/stable9/stable9.libraries.yml
index 828fdd4aa16d..98535a37153f 100644
--- a/core/themes/stable9/stable9.libraries.yml
+++ b/core/themes/stable9/stable9.libraries.yml
@@ -8,8 +8,3 @@ normalize:
   css:
     base:
       css/core/assets/vendor/normalize-css/normalize.css: { weight: -20 }
-
-tour:
-  version: VERSION
-  js:
-    js/tour.js: {}
-- 
GitLab