function ThemeManager::alterForTheme
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Theme/ThemeManager.php \Drupal\Core\Theme\ThemeManager::alterForTheme()
- 10 core/lib/Drupal/Core/Theme/ThemeManager.php \Drupal\Core\Theme\ThemeManager::alterForTheme()
- 9 core/lib/Drupal/Core/Theme/ThemeManager.php \Drupal\Core\Theme\ThemeManager::alterForTheme()
- 8.9.x core/lib/Drupal/Core/Theme/ThemeManager.php \Drupal\Core\Theme\ThemeManager::alterForTheme()
@todo Should we cache some of these information?
Parameters
\Drupal\Core\Theme\ActiveTheme $theme: A manually specified theme.
string|array $type: A string describing the type of the alterable $data.
mixed $data: The variable that will be passed to $theme_TYPE_alter() implementations.
mixed $context1: (optional) An additional variable that is passed by reference.
mixed $context2: (optional) An additional variable that is passed by reference.
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 532
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 ['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 = $this->getThemeChain($theme);
$listeners = [];
$base_hook = $type . '_alter';
foreach ($theme_keys as $theme_key) {
$listeners = array_merge($listeners, $this->getImplementationsForTheme($theme_key, $base_hook));
if (isset($extra_types)) {
foreach ($extra_types as $extra_type) {
$hook = $extra_type . '_alter';
$listeners = array_merge($listeners, $this->getImplementationsForTheme($theme_key, $hook));
}
}
}
$listeners = array_filter($listeners);
foreach ($listeners as $callback) {
$callback($data, $context1, $context2);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.