Problem/Motivation

For Views integration, we are doing a 3 steps process.

1. altering the registry from a hook:

  #[Hook('theme_registry_alter')]
  public function themeRegistryAlter(array &$theme_registry): void {
    if ($this->adminContext->isAdminRoute()) {
      return;
    }
    $template_uri = $this->moduleExtensionList->getPath('display_builder_views') . '/templates';
    $theme_registry['views_view']['path'] = $template_uri;
  }

2. adding a display_builder variable from a preprocess_views_view hook.

3. Adding a condition to the related template

<div{{ attributes.addClass(classes) }}>
  {% if display_builder.0 %}
    {{ display_builder }}
  {% else %}
    {# Original view rendered as web/core/modules/views/templates/views-view.html.twig #}
   ...

In #3538186: ThemeRegistryAlter must fallback on default templates , a similar mechanism with hook_theme_registry_alter was replaced by a dynamic alteration of the registry and the direct load of the expected template:

    // We alter the registry here instead of implementing
    // hook_theme_registry_alter in order keep the alteration specific to each
    // page.
    $theme_registry = $this->themeRegistry->get();
    $template_uri = $this->modules->getPath('display_builder_page_layout') . '/templates';
    $runtime = $this->themeRegistry->getRuntime();
    $theme_registry['page']['path'] = $template_uri;
    $runtime->set('page', $theme_registry['page']);
    $theme_registry['region']['path'] = $template_uri;
    $runtime->set('region', $theme_registry['region']);

https://git.drupalcode.org/project/display_builder/-/blob/1.0.x/modules/...

Proposed resolution

Do we want to do the same for Views integration? Is it possible ? It will simplify the implementation, that's good, but is it at the price of performance?

Remaining tasks

Don't forget to update the schema in the documentation :)

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pdureau created an issue. See original summary.

pdureau’s picture

Assigned: Unassigned » mogtofu33
Status: Active » Needs review
Issue tags: -display_builder-1.0.0-beta +display_builder-1.0.0-alpha5

Moved to alpha5 because it may make [#3542796) easier

mogtofu33’s picture

Assigned: mogtofu33 » pdureau
Status: Needs review » Needs work
pdureau’s picture

Assigned: pdureau » mogtofu33
Status: Needs work » Needs review

  • mogtofu33 committed 6e4fbef3 on 1.0.x authored by pdureau
    #3540078 fix: dynamic theme registry alteration for Views and tests...
mogtofu33’s picture

Assigned: mogtofu33 » Unassigned
Status: Needs review » Fixed
pdureau’s picture

Status: Fixed » Closed (fixed)