(Pre)process functions for nested hook suggestions are not invoked reliably

Created on 16 April 2019, almost 6 years ago
Updated 13 September 2024, 4 months ago

Problem/Motivation

This issue is composed of two aspects:

  • when processing the theme registry nested hook suggestion are not always processed in the same order;
  • when nested hook suggestions are processed in the intended order (more generic suggestions first), not all preprocess functions are invoked.

Example

function mytheme_preprocess_links(&$variables) {
  // ...
}
function mytheme_preprocess_links__entity(&$variables) {
  // ...
}
function mytheme_preprocess_links__entity__node(&$variables) {
  // ...
}

Depending on the runtime conditions when the registry is processed, theme('links__entity__node') might end up in one of these two cases:

  • mytheme_preprocess_links__entity__node() and mytheme_preprocess_links__entity() are invoked;
  • mytheme_preprocess_links__entity__node() and mytheme_preprocess_links() are invoked.

I'd expect all three preprocess functions to be invoked.

Proposed resolution

  • Ensure that nested hook suggestions are always processed in a predictable order when processing the theme registry.
  • Merge (pre)process and include data so that the whole hierarchy is traversed when dealing with the most specific suggestion.

Remaining tasks

  • Validate the proposed solution
  • Write a patch
  • Review it

User interface changes

None

API changes

This will most definitely result in a behavior change, which could be considered a BC-breaking change. OTOH the current behavior can be very tricky, as the theme may behave differently on each theme registry rebuild.

Data model changes

None

Release notes snippet

TBD

🐛 Bug report
Status

Closed: won't fix

Version

3.0

Component

Code

Created by

🇮🇹Italy plach Venezia

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024