public static function Bootstrap::alter in Express 8
Manages theme alter hooks as classes and allows sub-themes to sub-class.
Parameters
string $function: The procedural function name of the alter (e.g. __FUNCTION__).
mixed $data: The variable that was passed to the hook_TYPE_alter() implementation 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.
11 calls to Bootstrap::alter()
- bootstrap_bootstrap_colorize_text_alter in themes/
contrib/ bootstrap/ bootstrap.theme - bootstrap_bootstrap_iconize_text_alter in themes/
contrib/ bootstrap/ bootstrap.theme - bootstrap_bootstrap_layouts_class_options_alter in themes/
contrib/ bootstrap/ bootstrap.theme - bootstrap_element_info_alter in themes/
contrib/ bootstrap/ bootstrap.theme - bootstrap_form_alter in themes/
contrib/ bootstrap/ bootstrap.theme
File
- themes/
contrib/ bootstrap/ src/ Bootstrap.php, line 173 - Contains \Drupal\bootstrap\Bootstrap.
Class
- Bootstrap
- The primary class for the Drupal Bootstrap base theme.
Namespace
Drupal\bootstrapCode
public static function alter($function, &$data, &$context1 = NULL, &$context2 = NULL) {
static $theme;
if (!isset($theme)) {
$theme = self::getTheme();
}
// Immediately return if the active theme is not Bootstrap based.
if (!$theme
->isBootstrap()) {
return;
}
// Extract the alter hook name.
$hook = Unicode::extractHook($function, 'alter');
// Handle form alters as a separate plugin.
if (strpos($hook, 'form') === 0 && $context1 instanceof FormStateInterface) {
$form_state = $context1;
$form_id = $context2;
// Due to a core bug that affects admin themes, we should not double
// process the "system_theme_settings" form twice in the global
// hook_form_alter() invocation.
// @see https://drupal.org/node/943212
if ($form_id === 'system_theme_settings') {
return;
}
// Keep track of the form identifiers.
$ids = [];
// Get the build data.
$build_info = $form_state
->getBuildInfo();
// Extract the base_form_id.
$base_form_id = !empty($build_info['base_form_id']) ? $build_info['base_form_id'] : FALSE;
if ($base_form_id) {
$ids[] = $base_form_id;
}
// If there was no provided form identifier, extract it.
if (!$form_id) {
$form_id = !empty($build_info['form_id']) ? $build_info['form_id'] : Unicode::extractHook($function, 'alter', 'form');
}
if ($form_id) {
$ids[] = $form_id;
}
// Retrieve a list of form definitions.
$form_manager = new FormManager($theme);
// Iterate over each form identifier and look for a possible plugin.
foreach ($ids as $id) {
/** @var \Drupal\bootstrap\Plugin\Form\FormInterface $form */
if ($form_manager
->hasDefinition($id) && ($form = $form_manager
->createInstance($id, [
'theme' => $theme,
]))) {
$data['#submit'][] = [
get_class($form),
'submitForm',
];
$data['#validate'][] = [
get_class($form),
'validateForm',
];
$form
->alterForm($data, $form_state, $form_id);
}
}
}
else {
// Retrieve a list of alter definitions.
$alter_manager = new AlterManager($theme);
/** @var \Drupal\bootstrap\Plugin\Alter\AlterInterface $class */
if ($alter_manager
->hasDefinition($hook) && ($class = $alter_manager
->createInstance($hook, [
'theme' => $theme,
]))) {
$class
->alter($data, $context1, $context2);
}
}
}