From 00712d6a4bea667d875dc80c15925a54a69289a0 Mon Sep 17 00:00:00 2001 From: Herve Donner Date: Thu, 30 Jul 2020 19:11:31 +0200 Subject: [PATCH] Issue #298: Incorrect "path" in hook_theme definitions when the theme that contains patterns is not active. --- .../UiPatterns/Pattern/LibraryPattern.php | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/modules/ui_patterns_library/src/Plugin/UiPatterns/Pattern/LibraryPattern.php b/modules/ui_patterns_library/src/Plugin/UiPatterns/Pattern/LibraryPattern.php index f57aad21..acb1b2ad 100644 --- a/modules/ui_patterns_library/src/Plugin/UiPatterns/Pattern/LibraryPattern.php +++ b/modules/ui_patterns_library/src/Plugin/UiPatterns/Pattern/LibraryPattern.php @@ -72,16 +72,37 @@ public function getThemeImplementation() { * Processed hook definition portion. */ protected function processCustomThemeHookProperty(PatternDefinition $definition) { - /** @var \Drupal\Core\Extension\Extension $module */ - $return = []; - if (!$definition->hasCustomThemeHook() && $this->moduleHandler->moduleExists($definition->getProvider())) { - $module = $this->moduleHandler->getModule($definition->getProvider()); - $return['path'] = $module->getPath() . '/templates'; + if (!$definition->hasCustomThemeHook()) { if ($this->templateExists($definition->getBasePath(), $definition->getTemplate())) { - $return['path'] = str_replace($this->root, '', $definition->getBasePath()); + return ['path' => str_replace($this->root, '', $definition->getBasePath())]; + } + + $provider = $definition->getProvider(); + $extension = $this->getProviderExtension($provider); + if ($extension) { + return ['path' => $extension->getPath() . '/templates']; } } - return $return; + return []; + } + + /** + * Get the extension (module or theme) for the given provider. + * + * @param string $provider + * The name of the provider. + * + * @return \Drupal\Core\Extension\Extension|null + * The extension or NULL if none found. + */ + protected function getProviderExtension($provider) { + if ($this->moduleHandler->moduleExists($provider)) { + return $this->moduleHandler->getModule($provider); + } + elseif ($this->themeHandler->themeExists($provider)) { + return $this->themeHandler->getTheme($provider); + } + return NULL; } /**