Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294883

Explicitly register template_preprocess callbacks in hook_theme()

$
0
0

Problem/Motivation

template_preprocess... functions are very unusual. They are the only thing in modules that's not prefixed by the module.

#3495943: Handle module preprocess functions as OOP hooks is struggling a bit with that and need to introduce the ability for modules to register them as hooks but not for themself but a "template" pseudo-module.

The reason they are important is order of preprocess callbacks. Currently, first is template_preprocess(), followed by the template_preprocess function for the specific theme definition/hook if it exists, then global regular preprocess functions such as contextual_preprocess() and finally regular specific module and then theme preprocess functions.

Steps to reproduce

Proposed resolution

I'm proposing a different approach, that instead of magically named callbacks with a special prefix, or OOP hooks registered for template, we put them explicitly into hook_theme as a callback. Similar to #pre_render, #process and the other callbacks you can register in an Element plugin.

A cleaner option would to make a theme definition/hook an actual class like a plugin an then it could have a preprocess() method. There are old issues for introducing that, but it's a far more complex step that requires bigger changes and performance testing.

This requires template_preprocess() to be removed first: #2340341: Move template_preprocess, _template_preprocess_default_variables into services

Remaining tasks

* Agree that this makes sense.
* Agree on the specific array key
* documentation updates and change record
* Follow-ups to convert remaining template_preprocess, possibly a meta with a few child issues and then a deprecation.

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 294883

Trending Articles