Adds a default set of helper variables for variable processors and templates.
This function is called for theme hooks implemented as templates only, not for theme hooks implemented as functions. This preprocess function is the first in the sequence of preprocessing and processing functions that is called when preparing variables for a template. See theme() for more details about the full sequence.
theme()
template_process()
function template_preprocess(&$variables, $hook, $info) {
// Tell all templates where they are located.
$variables['directory'] = path_to_theme();
// 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'] = NestedArray::mergeDeep($variables['attributes'], $variables[$key]['#attributes']);
}
}
}