function claro_preprocess_links__dropbutton

Same name in other branches
  1. 9 core/themes/claro/claro.theme \claro_preprocess_links__dropbutton()
  2. 10 core/themes/claro/claro.theme \claro_preprocess_links__dropbutton()
  3. 11.x core/themes/claro/claro.theme \claro_preprocess_links__dropbutton()

Implements hook_preprocess_HOOK() for links__dropbutton.

File

core/themes/claro/claro.theme, line 999

Code

function claro_preprocess_links__dropbutton(&$variables) {
    // Add the right CSS class for the dropbutton list that helps reducing FOUC.
    if (!empty($variables['links'])) {
        $variables['attributes']['class'][] = count($variables['links']) > 1 ? 'dropbutton--multiple' : 'dropbutton--single';
    }
    $item_classes = [
        'dropbutton__item',
    ];
    // Check that the dropbutton has a supported variant class.
    // @todo Revisit after https://www.drupal.org/node/3057581 is added.
    if (!empty($variables['attributes']['class'])) {
        if (array_search('dropbutton--small', $variables['attributes']['class'])) {
            $item_classes[] = 'dropbutton__item--small';
        }
        elseif (array_search('dropbutton--extrasmall', $variables['attributes']['class'])) {
            $item_classes[] = 'dropbutton__item--extrasmall';
        }
    }
    foreach ($variables['links'] as &$link_data) {
        $link_data['attributes']->addClass($item_classes);
    }
}

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