function template_preprocess_menu_local_action

Same name in other branches
  1. 9 core/includes/theme.inc \template_preprocess_menu_local_action()
  2. 8.9.x core/includes/menu.inc \template_preprocess_menu_local_action()
  3. 11.x core/includes/theme.inc \template_preprocess_menu_local_action()

Prepares variables for single local action link templates.

Default template: menu-local-action.html.twig.

Parameters

array $variables: An associative array containing:

  • element: A render element containing:

    • #link: A menu link array with 'title', 'url', and (optionally) 'localized_options' keys.

File

core/includes/theme.inc, line 1933

Code

function template_preprocess_menu_local_action(&$variables) {
    $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'],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.