function ThemeManagerInterface::alter
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Theme/ThemeManagerInterface.php \Drupal\Core\Theme\ThemeManagerInterface::alter()
- 10 core/lib/Drupal/Core/Theme/ThemeManagerInterface.php \Drupal\Core\Theme\ThemeManagerInterface::alter()
- 11.x core/lib/Drupal/Core/Theme/ThemeManagerInterface.php \Drupal\Core\Theme\ThemeManagerInterface::alter()
Passes alterable variables to specific $theme_TYPE_alter() implementations.
Executes an alter hook on the current theme. It also invokes alter hooks for all base themes.
$theme specifies the theme name of the active theme and all its base themes.
This dispatch function hands off the passed-in variables to type-specific $theme_TYPE_alter() implementations in the active theme. It ensures a consistent interface for all altering operations.
A maximum of 2 alterable arguments is supported. In case more arguments need to be passed and alterable, modules provide additional variables assigned by reference in the last $context argument:
$context = array(
'alterable' => &$alterable,
'unalterable' => $unalterable,
'foo' => 'bar',
);
$this->alter('mymodule_data', $alterable1, $alterable2, $context);
Note that objects are always passed by reference. If it is absolutely required that no implementation alters a passed object in $context, then an object needs to be cloned:
$context = array(
'unalterable_object' => clone $object,
);
$this->alter('mymodule_data', $data, $context);
Parameters
string|array $type: A string describing the type of the alterable $data. 'form', 'links', 'node_content', and so on are several examples. Alternatively can be an array, in which case $theme_TYPE_alter() is invoked for each value in the array. When Form API is using $this->alter() to execute both $theme_form_alter() and $theme_form_FORM_ID_alter() implementations, it passes array('form', 'form_' . $form_id) for $type.
mixed $data: The variable that will be passed to $theme_TYPE_alter() implementations to be altered. The type of this variable depends on the value of the $type argument. For example, when altering a 'form', $data will be a structured array. When altering a 'profile', $data will be an object.
mixed $context1: (optional) An additional variable that is passed by reference.
mixed $context2: (optional) An additional variable that is passed by reference. If more context needs to be provided to implementations, then this should be an associative array as described above.
See also
\Drupal\Core\Extension\ModuleHandlerInterface
1 method overrides ThemeManagerInterface::alter()
- 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/ ThemeManagerInterface.php, line 127
Class
- ThemeManagerInterface
- Provides a high level access to the active theme and methods to use it.
Namespace
Drupal\Core\ThemeCode
public function alter($type, &$data, &$context1 = NULL, &$context2 = NULL);
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.