Skip to content

Doesn't work with multi-theme sites #308

@WidgetsBurritos

Description

@WidgetsBurritos

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.

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