Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vever001 opened this issue Jul 30, 2020 · 2 comments

Comments

@vever001
Copy link

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.

@donquixote
Copy link

There is something else going on here.

        $return['path'] = str_replace($this->root, '', $definition->getBasePath());

The str_replace() produces a path with leading slash.
E.g.

$definition_base_path = '/var/www/html/web/modules/custom/my_patterns/templates/patterns/my_pattern';
$root = '/var/www/html/web';
$path = str_replace($root, '', $definition_base_path);
print $path === '/modules/custom/my_patterns/templates/patterns/my_pattern' ? 'problem' : 'ok';

(I assume it is normal that $root won't have a trailing slash)
I wonder why this is not more wildly occuring.

@vever001 From looking at the code, I don't think your PR would fix this..

@mika2na
Copy link

mika2na commented Oct 13, 2022

Moved to drupal.org : https://www.drupal.org/project/ui_patterns/issues/3315219

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants