function ShortcutThemeHooks::preprocessPageTitleOlivero
Olivero-specific preprocessing for the page title.
Wraps the title and shortcut link in a div for positioning, and removes the shortcut link on the front page.
Parameters
array $variables: An associative array of variables.
1 call to ShortcutThemeHooks::preprocessPageTitleOlivero()
- ShortcutThemeHooks::preprocessPageTitle in core/
modules/ shortcut/ src/ Hook/ ShortcutThemeHooks.php - Implements hook_preprocess_HOOK() for page title templates.
File
-
core/
modules/ shortcut/ src/ Hook/ ShortcutThemeHooks.php, line 141
Class
- ShortcutThemeHooks
- Hook implementations for shortcut.
Namespace
Drupal\shortcut\HookCode
protected function preprocessPageTitleOlivero(array &$variables) : void {
// Since the title and the shortcut link are both block level elements,
// positioning them next to each other is much simpler with a wrapper div.
if (!empty($variables['title_suffix']['add_or_remove_shortcut']) && $variables['title']) {
// Add a wrapper div using the title_prefix and title_suffix render
// elements.
$variables['title_prefix']['shortcut_wrapper'] = [
'#markup' => '<div class="shortcut-wrapper">',
'#weight' => 100,
];
$variables['title_suffix']['shortcut_wrapper'] = [
'#markup' => '</div>',
'#weight' => -99,
];
// Make sure the shortcut link is the first item in title_suffix.
$variables['title_suffix']['add_or_remove_shortcut']['#weight'] = -100;
}
// Unset shortcut link on front page.
$variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage();
if ($variables['is_front'] === TRUE) {
unset($variables['title_suffix']['add_or_remove_shortcut']);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.