Views with an overridden twig template don't fire a preprocess event

Created on 1 July 2024, 9 months ago

Problem

Having, for example, a twig in the active theme views-view--product-listing--page-1.html.twig that corresponds with the theme function views_view__product_listing__page_1 makes the module not to dispatch any event since the hook name is not recognized by the factory.

Reading the docs doesn't help figuring out the correct way

Steps to reproduce

Override a view with a template and make an event subscriber for views.

Proposed resolution

When processing the hook name for a preprocess take only the part before "__" if there is one. This makes views_view__product_listing__page_1 into views_view, which is correctly handled. The original name will always be in the variables under "theme_hook_original".

Remaining tasks

Code. I don't mind writing it and adding tests if the proposal is accepted

API changes

All HOOK_NAME__FOOBAR theme hooks will start firing events for HOOK_NAME

Feature request
Status

Active

Version

4.1

Component

Code

Created by

🇪🇸Spain rodrigoaguilera Barcelona

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024