Change record status: 
Project: 
Introduced in branch: 
9.4.x
Introduced in version: 
9.4.0
Description: 

Drupal 9.4 changes the way that preprocess functions are called to allow callbacks instead of global functions. This had a side-effect of removing the undocumented ability to specify the third parameter($info) of hook_preprocess() by reference.

Most modules will not need to react to this change, however for any that do:

Before:

function mymodule_preprocess_foo(&$variables, $hook, &$info) {
}

After:

function mymodule_preprocess_foo(&$variables, $hook, $info) {
}
Impacts: 
Module developers
Themers

Comments

loopy1492’s picture

We have implemented this in one of our modules which has both mymodule__preprocess_page and mymodule_preprocess_taxonomy_term. This change does not seem to have had a detrimental effect on preprocess page, but for preprocess_taxonomy_term, our code seems to fail silently. There is no error. Our code just simpy does not execute.

```
// Set the theme template.
$info['theme path'] = drupal_get_path('module', 'mymodule');
$info['path'] = drupal_get_path('module', 'mymodule') . '/templates';
$info['template'] = 'keywords-term';
```

And yeah. This makes sense. If $info is no longer passed byref, then setting the info variable probably won't do anything.

Is there an existing set function for the $info variable here? I don't see one in the API but I could easily be overlooking it.

tfranz’s picture

/**
 * Implements hook_theme_registry_alter().
 */
function MYMODULE_theme_registry_alter(&$info) {
    $info['TEMPLATE']['theme path'] = \Drupal::moduleHandler()->getModule("MYMODULE")->getPath();
    $info['TEMPLATE']['path'] = \Drupal::moduleHandler()->getModule("MYMODULE")->getPath() . '/templates';
}