Add tests for 'override preprocess functions' functionality

Created on 1 September 2015, almost 10 years ago
Updated 22 July 2025, 12 days ago

Problem/Motivation

HOOK_theme() offers an option 'override preprocess functions'. Here's the relevant documentation. See https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21...

 *  - override preprocess functions: Set to TRUE when a theme does NOT want
 *     the standard preprocess functions to run. This can be used to give a
 *     theme FULL control over how variables are set. For example, if a theme
 *     wants total control over how certain variables in the page.html.twig are
 *     set, this can be set to true. Please keep in mind that when this is used
 *     by a theme, that theme becomes responsible for making sure necessary
 *     variables are set.

This is not implemented at all.

Proposed resolution

I have two propositions.

  1. Remove the feature.
    1. Remove documentation.
    2. Remove the code that mentions this parameter. It doesn't actually do anything relevant. See below.
  2. Fix the feature.

Here's the only place where this parameter is used in the code:

\Drupal\Core\Theme\Registry

        // Check for the override flag and prevent the cached variable
        // preprocessors from being used. This allows themes or theme engines
        // to remove variable preprocessors set earlier in the registry build.
        if (!empty($info['override preprocess functions'])) {
          // Flag not needed inside the registry.
          unset($result[$hook]['override preprocess functions']);
        }
        elseif (isset($cache[$hook]['preprocess functions']) && is_array($cache[$hook]['preprocess functions'])) {
          $info['preprocess functions'] = array_merge($cache[$hook]['preprocess functions'], $info['preprocess functions']);
        }

Seems that this code doesn't do it's job anymore.

Steps to reproduce

For example set the 'override preprocess functions' for the html hook like this:

core/includes/theme.inc

/**
 * Provides theme registration for themes across .inc files.
 */
function drupal_common_theme() {
  return array(
    // From theme.inc.
    'html' => array(
      'render element' => 'html',
      'override preprocess functions' => TRUE,
    ),
...

Rebuild the cache and put {{ dump() }} inside core/themes/classy/templates/layout/html.html.twig. See how all the variables are added from the template_preprocess() and template_preprocess_HOOK() functions.

Remaining tasks

Let's first discuss how we should resolve this and then write the decided tasks here.

User interface changes

None.

API changes

Data model changes

📌 Task
Status

Postponed: needs info

Version

11.0 🔥

Component

theme system

Created by

🇫🇮Finland jiv_e

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

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.

  • 🇺🇸United States smustgrave

    Thank you for creating this issue to improve Drupal.

    We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

Production build 0.71.5 2024