function template_preprocess
Same name in other branches
- 7.x includes/theme.inc \template_preprocess()
- 8.9.x core/includes/theme.inc \template_preprocess()
- 10 core/includes/theme.inc \template_preprocess()
- 11.x 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.
1 call to template_preprocess()
- ThemeManager::render in core/
lib/ Drupal/ Core/ Theme/ ThemeManager.php - Generates themed output.
6 string references to 'template_preprocess'
- RegistryLegacyTest::testSuggestionPreprocessFunctions in core/
tests/ Drupal/ KernelTests/ Core/ Theme/ RegistryLegacyTest.php - Tests the theme registry with theme functions with suggestions.
- RegistryTest::testMultipleSubThemes in core/
tests/ Drupal/ KernelTests/ Core/ Theme/ RegistryTest.php - Tests the theme registry with multiple subthemes.
- RegistryTest::testSuggestionPreprocessFunctions in core/
tests/ Drupal/ KernelTests/ Core/ Theme/ RegistryTest.php - Tests the theme registry with suggestions.
- RegistryTest::testThemeTemplatesRegisteredByModules in core/
tests/ Drupal/ KernelTests/ Core/ Theme/ RegistryTest.php - Tests theme-provided templates that are registered by modules.
- user_user_login in core/
modules/ user/ user.module - Implements hook_user_login().
File
-
core/
includes/ theme.inc, line 1267
Code
function template_preprocess(&$variables, $hook, $info) {
// Merge in variables that don't depend on hook and don't change during a
// single page request.
// Use the advanced drupal_static() pattern, since this is called very often.
static $drupal_static_fast;
if (!isset($drupal_static_fast)) {
$drupal_static_fast['default_variables'] =& drupal_static(__FUNCTION__);
}
$default_variables =& $drupal_static_fast['default_variables'];
if (!isset($default_variables)) {
$default_variables = _template_preprocess_default_variables();
}
$variables += $default_variables;
// 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.