Unverified Commit 108a6efd authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3123666 by smustgrave, larowlan, arunkumark, DuaelFr, acbramley, dpi,...

Issue #3123666 by smustgrave, larowlan, arunkumark, DuaelFr, acbramley, dpi, joshua1234511, Kristen Pol: Custom classes for pager links do not work with Claro theme
parent 0ac4b763
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -27,11 +27,13 @@ function pager_test_preprocess_pager(&$variables) {

  foreach ($variables['items']['pages'] as $index => &$pager_item) {
    $pager_item['attributes']['pager-test'] = 'yes';
    $pager_item['attributes']->addClass('lizards');
  }
  unset($pager_item);

  foreach (['first', 'previous', 'next', 'last'] as $special_pager_item) {
    if (isset($variables['items'][$special_pager_item])) {
      $variables['items'][$special_pager_item]['attributes']->addClass('lizards');
      $variables['items'][$special_pager_item]['attributes']['pager-test'] = $special_pager_item;
    }
  }
+29 −1
Original line number Diff line number Diff line
@@ -18,9 +18,11 @@ class ClaroTest extends BrowserTestBase {
   * There's currently no way for Claro to provide a default and have valid
   * configuration as themes cannot react to a module install.
   *
   * Install dblog and pager_test for testing of pager attributes.
   *
   * @var string[]
   */
  protected static $modules = ['shortcut'];
  protected static $modules = ['dblog', 'shortcut', 'pager_test'];

  /**
   * {@inheritdoc}
@@ -68,4 +70,30 @@ public function testIsUninstallable() {
    $this->assertSession()->pageTextContains('The Claro theme has been uninstalled.');
  }

  /**
   * Tests pager attribute is present using pager_test.
   */
  public function testPagerAttribute(): void {
    // Insert 300 log messages.
    $logger = $this->container->get('logger.factory')->get('pager_test');
    for ($i = 0; $i < 300; $i++) {
      $logger->debug($this->randomString());
    }

    $this->drupalLogin($this->drupalCreateUser(['access site reports']));

    $this->drupalGet('admin/reports/dblog', ['query' => ['page' => 1]]);
    $this->assertSession()->statusCodeEquals(200);
    $elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
    $this->assertNotEmpty($elements, 'Pager found.');

    // Check all links for pager-test attribute.
    foreach ($elements as $page => $element) {
      $link = $element->find('css', 'a');
      $this->assertNotEmpty($link, "Link to page $page found.");
      $this->assertTrue($link->hasAttribute('pager-test'), 'Pager item has attribute pager-test');
      $this->assertTrue($link->hasClass('lizards'));
    }
  }

}
+5 −5
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@
      {% if items.first %}
        {% apply spaceless %}
        <li class="pager__item pager__item--action pager__item--first">
          <a href="{{ items.first.href }}" class="pager__link pager__link--action-link" title="{{ 'Go to first page'|t }}"{{ items.first.attributes|without('href', 'title') }}>
          <a href="{{ items.first.href }}" title="{{ 'Go to first page'|t }}"{{ items.first.attributes|without('href', 'title').addClass('pager__link', 'pager__link--action-link') }}>
            <span class="visually-hidden">{{ 'First page'|t }}</span>
            <span class="pager__item-title pager__item-title--backwards" aria-hidden="true">
              {{ items.first.text|default('First'|t)|replace({'«': ''}) }}
@@ -56,7 +56,7 @@
      {% if items.previous %}
        {% apply spaceless %}
        <li class="pager__item pager__item--action pager__item--previous">
          <a href="{{ items.previous.href }}" class="pager__link pager__link--action-link" title="{{ 'Go to previous page'|t }}" rel="prev"{{ items.previous.attributes|without('href', 'title', 'rel') }}>
          <a href="{{ items.previous.href }}" title="{{ 'Go to previous page'|t }}" rel="prev"{{ items.previous.attributes|without('href', 'title', 'rel').addClass('pager__link', 'pager__link--action-link') }}>
            <span class="visually-hidden">{{ 'Previous page'|t }}</span>
            <span class="pager__item-title pager__item-title--backwards" aria-hidden="true">
              {{ items.previous.text|default('Previous'|t)|replace({'‹': ''}) }}
@@ -80,7 +80,7 @@
          {% else %}
            {% set title = 'Go to page @key'|t({'@key': key}) %}
          {% endif %}
          <a href="{{ item.href }}" class="pager__link{{ current == key ? ' is-active' }}" title="{{ title }}"{{ item.attributes|without('href', 'title', 'class') }}>
          <a href="{{ item.href }}" title="{{ title }}"{{ item.attributes|without('href', 'title').addClass(['pager__link', current == key ? ' is-active']) }}>
            <span class="visually-hidden">
              {{ current == key ? 'Current page'|t : 'Page'|t }}
            </span>
@@ -99,7 +99,7 @@
      {% if items.next %}
        {% apply spaceless %}
        <li class="pager__item pager__item--action pager__item--next">
          <a href="{{ items.next.href }}" class="pager__link pager__link--action-link" title="{{ 'Go to next page'|t }}" rel="next"{{ items.next.attributes|without('href', 'title', 'rel') }}>
          <a href="{{ items.next.href }}" title="{{ 'Go to next page'|t }}" rel="next"{{ items.next.attributes|without('href', 'title', 'rel').addClass('pager__link', 'pager__link--action-link') }}>
            <span class="visually-hidden">{{ 'Next page'|t }}</span>
            <span class="pager__item-title pager__item-title--forward" aria-hidden="true">
              {{ items.next.text|default('Next'|t)|replace({'›': ''}) }}
@@ -113,7 +113,7 @@
      {% if items.last %}
        {% apply spaceless %}
        <li class="pager__item pager__item--action pager__item--last">
          <a href="{{ items.last.href }}" class="pager__link pager__link--action-link" title="{{ 'Go to last page'|t }}"{{ items.last.attributes|without('href', 'title') }}>
          <a href="{{ items.last.href }}" title="{{ 'Go to last page'|t }}"{{ items.last.attributes|without('href', 'title').addClass('pager__link', 'pager__link--action-link') }}>
            <span class="visually-hidden">{{ 'Last page'|t }}</span>
            <span class="pager__item-title pager__item-title--forward" aria-hidden="true">
              {{ items.last.text|default('Last'|t)|replace({'»': ''}) }}