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.
- Remove the feature.
- Remove documentation.
- Remove the code that mentions this parameter. It doesn't actually do anything relevant. See below.
- 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