function claro_preprocess_links

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

Implements hook_preprocess_HOOK() for links.

File

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

Code

function claro_preprocess_links(&$variables) {
    foreach ($variables['links'] as $links_item) {
        if (!empty($links_item['link']) && !empty($links_item['link']['#url']) && $links_item['link']['#url'] instanceof Url) {
            if ($links_item['link']['#url']->isRouted()) {
                switch ($links_item['link']['#url']->getRouteName()) {
                    case 'system.theme_settings_theme':
                        $links_item['link'] = _claro_convert_link_to_action_link($links_item['link'], 'cog', 'small');
                        break;
                    case 'system.theme_uninstall':
                        $links_item['link'] = _claro_convert_link_to_action_link($links_item['link'], 'ex', 'small');
                        break;
                    case 'system.theme_set_default':
                    case 'system.theme_install':
                        $links_item['link'] = _claro_convert_link_to_action_link($links_item['link'], 'checkmark', 'small');
                        break;
                }
            }
        }
    }
    // This makes it so array keys of #links items are added as a class. This
    // functionality was removed in Drupal 8.1, but still necessary in some
    // instances.
    // @todo remove in https://drupal.org/node/3120962
    if (!empty($variables['links'])) {
        foreach ($variables['links'] as $key => $value) {
            if (!is_numeric($key)) {
                $class = Html::getClass($key);
                $variables['links'][$key]['attributes']->addClass($class);
            }
        }
    }
}

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