function PreprocessHooks::menuLocalTasks
Same name and namespace in other branches
- 11.x core/themes/admin/src/Hook/PreprocessHooks.php \Drupal\admin\Hook\PreprocessHooks::menuLocalTasks()
Implements hook_preprocess_HOOK() for menu-local-tasks templates.
Use preprocess hook to set #attached to child elements because they will be processed by Twig and \Drupal::service('renderer')->render() will be invoked.
Attributes
#[Hook('preprocess_menu_local_tasks')]
File
-
core/
themes/ admin/ src/ Hook/ PreprocessHooks.php, line 946
Class
- PreprocessHooks
- Provides preprocess implementations.
Namespace
Drupal\admin\HookCode
public function menuLocalTasks(array &$variables) : void {
if (!empty($variables['primary'])) {
$variables['primary']['#attached'] = [
'library' => [
'admin/drupal.nav-tabs',
],
];
}
elseif (!empty($variables['secondary'])) {
$variables['secondary']['#attached'] = [
'library' => [
'admin/drupal.nav-tabs',
],
];
}
foreach (Element::children($variables['primary']) as $key) {
$variables['primary'][$key]['#level'] = 'primary';
}
foreach (Element::children($variables['secondary']) as $key) {
$variables['secondary'][$key]['#level'] = 'secondary';
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.