function template_preprocess

Same name in other branches
  1. 7.x includes/theme.inc \template_preprocess()
  2. 9 core/includes/theme.inc \template_preprocess()
  3. 8.9.x core/includes/theme.inc \template_preprocess()
  4. 10 core/includes/theme.inc \template_preprocess()

Adds a default set of helper variables for preprocessors and templates.

This function is called for every theme hook. It is the first in the sequence of preprocessing functions called when preparing variables for a template.

See the Default theme implementations topic for details.

Deprecated

in drupal:11.2.0 and is removed from drupal:12.0.0. There is no replacement, default preprocess variables are added for all theme hooks directly in \Drupal\Core\Theme\ThemeManager.

See also

https://www.drupal.org/node/2340341

File

core/includes/theme.inc, line 1070

Code

function template_preprocess(&$variables, $hook, $info) {
    @trigger_error('template_preprocess() is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. There is no replacement, default preprocess variables are added for all theme hooks directly in \\Drupal\\Core\\Theme\\ThemeManager. See https://www.drupal.org/node/2340341', E_USER_DEPRECATED);
    $themeManager = \Drupal::service('theme.manager');
    // ThemeManager::getDefaultTemplateVariables() is not on the interface, it is
    // internal and only public for backwards compatibility, verify it really
    // exists.
    if (method_exists($themeManager, 'getDefaultTemplateVariables')) {
        $variables += $themeManager->getDefaultTemplateVariables();
    }
    // When theming a render element, merge its #attributes into
    // $variables['attributes'].
    if (isset($info['render element'])) {
        $key = $info['render element'];
        if (isset($variables[$key]['#attributes'])) {
            $variables['attributes'] = AttributeHelper::mergeCollections($variables['attributes'], $variables[$key]['#attributes']);
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.