function PreprocessHooks::links

Same name and namespace in other branches
  1. main core/themes/admin/src/Hook/PreprocessHooks.php \Drupal\admin\Hook\PreprocessHooks::links()

Implements hook_preprocess_HOOK() for links.

Attributes

#[Hook('preprocess_links')]

File

core/themes/admin/src/Hook/PreprocessHooks.php, line 767

Class

PreprocessHooks
Provides preprocess implementations.

Namespace

Drupal\admin\Hook

Code

public function links(array &$variables) : void {
  foreach ($variables['links'] as $links_item) {
    if (!empty($links_item['link']) && !empty($links_item['link']['#url']) && $links_item['link']['#url'] instanceof Url && $links_item['link']['#url']->isRouted()) {
      switch ($links_item['link']['#url']->getRouteName()) {
        case 'system.theme_settings_theme':
          $links_item['link'] = Helper::convertLinkToActionLink($links_item['link'], 'cog', 'small');
          break;

        case 'system.theme_uninstall':
          $links_item['link'] = Helper::convertLinkToActionLink($links_item['link'], 'ex', 'small');
          break;

        case 'system.theme_set_default':
          $links_item['link'] = Helper::convertLinkToActionLink($links_item['link'], 'checkmark', 'small');
          break;

        case 'system.theme_install':
          $links_item['link'] = Helper::convertLinkToActionLink($links_item['link'], 'plus', '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.