Skip to content

Incorrect "path" in hook_theme definitions when the theme that contains patterns is not active #298

@vever001

Description

@vever001

If we are on the admin theme, and we have pattern definitions inside another theme (e.g: your main theme), then the path in hook_theme() definitions are not correct.
This is because LibraryPattern::processCustomThemeHookProperty only takes into account modules.

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 ($this->templateExists($definition->getBasePath(), $definition->getTemplate())) {
      $return['path'] = str_replace($this->root, '', $definition->getBasePath());
    }
  }
  return $return;
}

This breaks for example the preview when we are in the Views admin and other patterns usages when the active theme is not the one that contains the definitions.
I will create a PR shortly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions