--- a/gin_toolbar.module +++ b/gin_toolbar.module @@ -179,29 +179,54 @@ * Attach libraries. */ function gin_toolbar_library_info_alter(&$libraries, $extension) { + // Gin's own .info.yml already adds these same 'gin/...' dependencies via + // libraries-extend whenever Gin is actually the active theme, which is + // cache-safe because Drupal's library cache is keyed by active theme + // (see LibraryDiscoveryCollector::getCid() and AssetResolver's css/js + // cache keys). The additions below are only meaningful, then, for + // bridging Gin's dialog/ckeditor/media_library styling into contexts + // where Gin ISN'T the active theme (e.g. the frontend theme, or a theme + // negotiator forcing something else on admin routes) — but that decision + // can't safely depend on anything other than the active theme name + // (e.g. the current user), since nothing besides active theme partitions + // those caches. So, unlike gin_toolbar's other cross-theme bridging (see + // _gin_toolbar_gin_is_active(), used by gin_toolbar_preprocess_html() and + // gin_toolbar_page_attachments_alter()), skip adding the 'gin/...' + // dependencies here entirely and let Gin's own libraries-extend be the + // only source of them. + $active_theme_is_gin = \Drupal::theme()->getActiveTheme()->getName() === 'gin'; + if ($extension == 'core' && isset($libraries['drupal.dialog'])) { $libraries['drupal.dialog']['dependencies'][] = 'claro/claro.drupal.dialog'; - $libraries['drupal.dialog']['dependencies'][] = 'gin/dialog'; + if ($active_theme_is_gin) { + $libraries['drupal.dialog']['dependencies'][] = 'gin/dialog'; + } } - if ($extension == 'core' && isset($libraries['ckeditor'])) { + if ($extension == 'core' && isset($libraries['ckeditor']) && $active_theme_is_gin) { $libraries['ckeditor']['dependencies'][] = 'gin/gin_ckeditor'; $libraries['ckeditor']['dependencies'][] = 'gin/ckeditor'; } if ($extension == 'core' && isset($libraries['drupal.ajax'])) { $libraries['drupal.ajax']['dependencies'][] = 'claro/ajax'; - $libraries['drupal.ajax']['dependencies'][] = 'gin/ajax'; + if ($active_theme_is_gin) { + $libraries['drupal.ajax']['dependencies'][] = 'gin/ajax'; + } } if ($extension == 'media_library' && isset($libraries['widget'])) { $libraries['widget']['dependencies'][] = 'claro/media_library.theme'; - $libraries['widget']['dependencies'][] = 'gin/media_library'; + if ($active_theme_is_gin) { + $libraries['widget']['dependencies'][] = 'gin/media_library'; + } } if ($extension == 'media_library' && isset($libraries['view'])) { $libraries['view']['dependencies'][] = 'claro/media_library.theme'; - $libraries['view']['dependencies'][] = 'gin/media_library'; + if ($active_theme_is_gin) { + $libraries['view']['dependencies'][] = 'gin/media_library'; + } } if ($extension == 'workbench' && isset($libraries['workbench.toolbar'])) {