function hook_template_preprocess_default_variables_alter

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/theme.api.php \hook_template_preprocess_default_variables_alter()
  2. 8.9.x core/lib/Drupal/Core/Render/theme.api.php \hook_template_preprocess_default_variables_alter()
  3. 11.x core/lib/Drupal/Core/Render/theme.api.php \hook_template_preprocess_default_variables_alter()

Alter the default, hook-independent variables for all templates.

Allows modules to provide additional default template variables or manipulate existing. This hook is invoked from template_preprocess() after basic default template variables have been set up and before the next template preprocess function is 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 static cache in template_preprocess() when needed:

drupal_static_reset('template_preprocess');

See user_template_preprocess_default_variables_alter() for an example.

Parameters

array $variables: An associative array of default template variables, as set up by _template_preprocess_default_variables(). Passed by reference.

See also

template_preprocess()

_template_preprocess_default_variables()

Related topics

1 function implements hook_template_preprocess_default_variables_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

user_template_preprocess_default_variables_alter in core/modules/user/user.module
Implements hook_template_preprocess_default_variables_alter().
1 invocation of hook_template_preprocess_default_variables_alter()
_template_preprocess_default_variables in core/includes/theme.inc
Returns hook-independent variables to template_preprocess().

File

core/lib/Drupal/Core/Render/theme.api.php, line 1361

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.