ui_patterns icon indicating copy to clipboard operation
ui_patterns copied to clipboard

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

Open vever001 opened this issue 4 years ago • 2 comments

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.

vever001 avatar Jul 30 '20 17:07 vever001

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..

donquixote avatar May 18 '21 19:05 donquixote

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

mika2na avatar Oct 13 '22 18:10 mika2na