function hook_template_preprocess_default_variables_alter
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Render/theme.api.php \hook_template_preprocess_default_variables_alter()
- 8.9.x core/lib/Drupal/Core/Render/theme.api.php \hook_template_preprocess_default_variables_alter()
- 10 core/lib/Drupal/Core/Render/theme.api.php \hook_template_preprocess_default_variables_alter()
Alter the default variables for all templates.
Allows modules to provide additional default template variables or manipulate existing. This hook is invoked from ThemeManager service's getDefaultTemplateVariables() method after basic default template variables have been set up and before the template preprocess functions are invoked.
Note that the default template variables are statically cached within a request. When adding a template variable that depends on other context, it is your responsibility to appropriately reset the default variables:
\Drupal::service('theme.manager)->resetActiveTheme()
See user_template_preprocess_default_variables_alter() for an example.
Parameters
array $variables: An associative array of default template variables, as set up by Drupal/Core/Theme/ThemeManagerInterface::getDefaultTemplateVariables(). Passed by reference.
Related topics
1 function implements hook_template_preprocess_default_variables_alter()
Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.
- UserHooks::templatePreprocessDefaultVariablesAlter in core/
modules/ user/ src/ Hook/ UserHooks.php - Implements hook_template_preprocess_default_variables_alter().
1 invocation of hook_template_preprocess_default_variables_alter()
- ThemeManager::getDefaultTemplateVariables in core/
lib/ Drupal/ Core/ Theme/ ThemeManager.php - Returns default template variables.
File
-
core/
lib/ Drupal/ Core/ Render/ theme.api.php, line 1370
Code
function hook_template_preprocess_default_variables_alter(&$variables) {
$variables['is_admin'] = \Drupal::currentUser()->hasPermission('access administration pages');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.