ui_patterns
ui_patterns copied to clipboard
Incorrect "path" in hook_theme definitions when the theme that contains patterns is not active
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.
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..
Moved to drupal.org : https://www.drupal.org/project/ui_patterns/issues/3315219