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

Doesn't work with multi-theme sites #308

Open
WidgetsBurritos opened this issue Sep 25, 2020 · 1 comment
Open

Doesn't work with multi-theme sites #308

WidgetsBurritos opened this issue Sep 25, 2020 · 1 comment

Comments

@WidgetsBurritos
Copy link

Problem Statement:
Our website uses the context module to use multiple themes depending on various criteria (such as content type). When used in combination with the component_blocks + ui_patterns modules, we never see any component blocks in the toolbar, unless they're associated with the default theme. The reason for this is this block of code:

  /**
   * Create a list of all directories to scan.
   *
   * This includes all module directories and directories of the default theme
   * and all of its possible base themes.
   *
   * @return array
   *   An array containing directory paths keyed by their extension name.
   */
  protected function getDirectories() {
    $default_theme = $this->themeHandler->getDefault();
    $base_themes = $this->themeHandler->getBaseThemes($this->themeHandler->listInfo(), $default_theme);
    $theme_directories = $this->themeHandler->getThemeDirectories();

    $directories = [];
    if (isset($theme_directories[$default_theme])) {
      $directories[$default_theme] = $theme_directories[$default_theme];
      foreach ($base_themes as $name => $theme) {
        $directories[$name] = $theme_directories[$name];
      }
    }

    return $directories + $this->moduleHandler->getModuleDirectories();
  }

It's explicitly only ever looking for the default theme, so it doesn't let sites with multiple themes to use patterns.

Proposed Solution

This is not the same issue as #304 but both could be solved the same way, per @vever001's suggestion: #304 (comment)

And the logic could be simplified to:

protected function getDirectories() {
  return $this->moduleHandler->getModuleDirectories() + $this->themeHandler->getThemeDirectories();
}

Same logic as \Drupal\Core\Layout\LayoutPluginManager and \Drupal\breakpoint\BreakpointManager.

Since that's the way core does it, it makes the most sense to replicate that behavior.

It is also worth noting this would not get fixed by the PR in #305.

@WidgetsBurritos
Copy link
Author

Oh also, FWIW we can't just look at the active theme instead of the default theme either. I tested swapping $this->themeHandler->getDefault(); with \Drupal::service('theme.manager')->getActiveTheme()->getName();, but when used with layout builder it seemed to be grabbing the admin theme, not the theme of the current page.

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

1 participant