Custom classes for pager links do not work with Claro theme

Created on 31 March 2020, over 4 years ago
Updated 3 March 2023, almost 2 years ago

Problem/Motivation

When using the Claro theme, custom classes added to pager links do not appear. Claro defines its own class for pager links but does not add any custom classes. Normally, custom classes can be added to themes using template hooks.

Steps to reproduce

  1. Install fresh Drupal setup
  2. Enable Claro theme
  3. Create a view with pager enabled
  4. Add a template_preprocess_pager hook and add a test class (see example below)
  5. Go to the view and inspect the pager markup
  6. Result: The test class is not added to the pager
  7. Expected: The test class is added to the pager

Example test Hook:

/**
 * Implements template_preprocess_pager().
 */
function claro_preprocess_pager(&$vars) {
  if (isset($vars['pager'])) {
    if (count($vars['items'])) {
      foreach ($vars['items'] as $key => $value) {
        // print_r('<pre>');
        // var_dump($value);
        if (!empty($value['attributes'])) {
          $vars['items'][$key]['attributes']->addClass('test-pager-class');
        }
        else {
          if (count($value) > 3) {
            foreach ($value as $subKey => $subValue) {
              if (!empty($subValue['attributes'])) {
                $vars['items'][$key][$subKey]['attributes']->addClass('test-pager-class');
              }
            }
          }
        }
      }
    }
  }
}

Screenshots

Before:

After:

Proposed resolution

Update pager.html.twig to inject custom classes. See other themes for examples.

Remaining tasks

  1. Commit

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Fixed

Version

10.1

Component
Claro 

Last updated about 6 hours ago

Created by

🇦🇺Australia dpi Perth, Australia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024