class MenuPreprocess
Menu theme preprocess.
@internal
Hierarchy
- class \Drupal\Core\Menu\MenuPreprocess
Expanded class hierarchy of MenuPreprocess
2 files declare their use of MenuPreprocess
- theme.inc in core/
includes/ theme.inc - The theme system, which controls the output of Drupal.
- ThemeCommonElements.php in core/
lib/ Drupal/ Core/ Theme/ ThemeCommonElements.php
1 string reference to 'MenuPreprocess'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses MenuPreprocess
File
-
core/
lib/ Drupal/ Core/ Menu/ MenuPreprocess.php, line 10
Namespace
Drupal\Core\MenuView source
class MenuPreprocess {
/**
* Prepares variables for single local task link templates.
*
* Default template: menu-local-task.html.twig.
*
* @param array $variables
* An associative array containing:
* - element: A render element containing:
* - #link: A menu link array with 'title', 'url', and (optionally)
* 'localized_options' keys.
* - #active: A boolean indicating whether the local task is active.
*/
public function preprocessMenuLocalTask(array &$variables) : void {
$link = $variables['element']['#link'];
$link += [
'localized_options' => [],
];
$link_text = $link['title'];
if (!empty($variables['element']['#active'])) {
$variables['is_active'] = TRUE;
}
$link['localized_options']['set_active_class'] = TRUE;
$variables['link'] = [
'#type' => 'link',
'#title' => $link_text,
'#url' => $link['url'],
'#options' => $link['localized_options'],
];
}
/**
* Prepares variables for single local action link templates.
*
* Default template: menu-local-action.html.twig.
*
* @param array $variables
* An associative array containing:
* - element: A render element containing:
* - #link: A menu link array with 'title', 'url', and (optionally)
* 'localized_options' keys.
*/
public function preprocessMenuLocalAction(array &$variables) : void {
$link = $variables['element']['#link'];
$link += [
'localized_options' => [],
];
$link['localized_options']['attributes']['class'][] = 'button';
$link['localized_options']['attributes']['class'][] = 'button-action';
$link['localized_options']['set_active_class'] = TRUE;
$variables['link'] = [
'#type' => 'link',
'#title' => $link['title'],
'#options' => $link['localized_options'],
'#url' => $link['url'],
];
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
MenuPreprocess::preprocessMenuLocalAction | public | function | Prepares variables for single local action link templates. |
MenuPreprocess::preprocessMenuLocalTask | public | function | Prepares variables for single local task link templates. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.