public function ThemeManager::alterForTheme in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Theme/ThemeManager.php \Drupal\Core\Theme\ThemeManager::alterForTheme()
@todo Should we cache some of these information?
Overrides ThemeManagerInterface::alterForTheme
1 call to ThemeManager::alterForTheme()
- ThemeManager::alter in core/
lib/ Drupal/ Core/ Theme/ ThemeManager.php - Passes alterable variables to specific $theme_TYPE_alter() implementations.
File
- core/
lib/ Drupal/ Core/ Theme/ ThemeManager.php, line 414
Class
- ThemeManager
- Provides the default implementation of a theme manager.
Namespace
Drupal\Core\ThemeCode
public function alterForTheme(ActiveTheme $theme, $type, &$data, &$context1 = NULL, &$context2 = NULL) {
// Most of the time, $type is passed as a string, so for performance,
// normalize it to that. When passed as an array, usually the first item in
// the array is a generic type, and additional items in the array are more
// specific variants of it, as in the case of array('form', 'form_FORM_ID').
if (is_array($type)) {
$extra_types = $type;
$type = array_shift($extra_types);
// Allow if statements in this function to use the faster isset() rather
// than !empty() both when $type is passed as a string, or as an array with
// one item.
if (empty($extra_types)) {
unset($extra_types);
}
}
$theme_keys = array_keys($theme
->getBaseThemeExtensions());
$theme_keys[] = $theme
->getName();
$functions = [];
foreach ($theme_keys as $theme_key) {
$function = $theme_key . '_' . $type . '_alter';
if (function_exists($function)) {
$functions[] = $function;
}
if (isset($extra_types)) {
foreach ($extra_types as $extra_type) {
$function = $theme_key . '_' . $extra_type . '_alter';
if (function_exists($function)) {
$functions[] = $function;
}
}
}
}
foreach ($functions as $function) {
$function($data, $context1, $context2);
}
}