Unverified Commit f0823b6c authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2454289 by laravz, pguillard, alexpott, ajzetat, borisson_, joachim,...

Issue #2454289 by laravz, pguillard, alexpott, ajzetat, borisson_, joachim, zulljin, mschudders, zviryatko, andrewmacpherson, ksemihin, nicrodgers, berdir, smustgrave, rob holmes, joseph.olstad, eugene.brit: Attribute hreflang not allowed on element li at this point

(cherry picked from commit 7c721031)
parent 4624601e
Loading
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -198,7 +198,8 @@ public static function setLinkActiveClass($html_markup, $current_path, $is_front

      // The language of an active link is equal to the current language.
      if ($add_active && $url_language) {
        if ($node->hasAttribute('hreflang') && $node->getAttribute('hreflang') !== $url_language) {
        $attribute = $node->nodeName === 'a' ? 'hreflang' : 'data-drupal-language';
        if ($node->hasAttribute($attribute) && $node->getAttribute($attribute) !== $url_language) {
          $add_active = FALSE;
        }
      }
+1 −1
Original line number Diff line number Diff line
@@ -186,7 +186,7 @@ public function preprocessLinks(array &$variables): void {
            $link_element['#options']['set_active_class'] = TRUE;

            if (!empty($link['language'])) {
              $li_attributes['hreflang'] = $link['language']->getId();
              $li_attributes['data-drupal-language'] = $link['language']->getId();
            }

            // Add a "data-drupal-link-query" attribute to let the
+11 −3
Original line number Diff line number Diff line
@@ -40,10 +40,18 @@
      // Add language filtering.
      selectors = [].concat(
        // Links without any hreflang attributes (most of them).
        originalSelectors.map((selector) => `${selector}:not([hreflang])`),
        // Links with hreflang equals to the current language.
        originalSelectors.map(
          (selector) => `${selector}[hreflang="${path.currentLanguage}"]`,
          (selector) =>
            `${selector}:not([data-drupal-language]):not([hreflang])`,
        ),
        // Links li with data-drupal-language equals to the current language.
        originalSelectors.map(
          (selector) =>
            `li${selector}[data-drupal-language="${path.currentLanguage}"]`,
        ),
        // Links a with hreflang equals to the current language.
        originalSelectors.map(
          (selector) => `a${selector}[hreflang="${path.currentLanguage}"]`,
        ),
      );

+10 −10
Original line number Diff line number Diff line
@@ -123,7 +123,7 @@ protected function doTestHomePageLinks($block_label): void {
    $labels = [];
    foreach ($language_switchers as $list_item) {
      $list_items[] = [
        'hreflang' => $list_item->getAttribute('hreflang'),
        'data-drupal-language' => $list_item->getAttribute('data-drupal-language'),
        'data-drupal-link-system-path' => $list_item->getAttribute('data-drupal-link-system-path'),
      ];

@@ -137,11 +137,11 @@ protected function doTestHomePageLinks($block_label): void {
    }
    $expected_list_items = [
      0 => [
        'hreflang' => 'en',
        'data-drupal-language' => 'en',
        'data-drupal-link-system-path' => '<front>',
      ],
      1 => [
        'hreflang' => 'fr',
        'data-drupal-language' => 'fr',
        'data-drupal-link-system-path' => '<front>',
      ],
    ];
@@ -183,7 +183,7 @@ protected function doTestLanguageBlockAuthenticated($block_label): void {
    $labels = [];
    foreach ($language_switchers as $list_item) {
      $list_items[] = [
        'hreflang' => $list_item->getAttribute('hreflang'),
        'data-drupal-language' => $list_item->getAttribute('data-drupal-language'),
        'data-drupal-link-system-path' => $list_item->getAttribute('data-drupal-link-system-path'),
      ];

@@ -195,8 +195,8 @@ protected function doTestLanguageBlockAuthenticated($block_label): void {
      $labels[] = $link->getText();
    }
    $expected_list_items = [
      0 => ['hreflang' => 'en', 'data-drupal-link-system-path' => 'user/2'],
      1 => ['hreflang' => 'fr', 'data-drupal-link-system-path' => 'user/2'],
      0 => ['data-drupal-language' => 'en', 'data-drupal-link-system-path' => 'user/2'],
      1 => ['data-drupal-language' => 'fr', 'data-drupal-link-system-path' => 'user/2'],
    ];
    $this->assertSame($expected_list_items, $list_items, 'The list items have the correct attributes that will allow the drupal.active-link library to mark them as active.');
    $expected_anchors = [
@@ -239,7 +239,7 @@ protected function doTestLanguageBlockAnonymous($block_label): void {
    ];
    $labels = [];
    foreach ($language_switchers as $list_item) {
      $langcode = $list_item->getAttribute('hreflang');
      $langcode = $list_item->getAttribute('data-drupal-language');
      if ($list_item->hasClass('is-active')) {
        $links['active'][] = $langcode;
      }
@@ -284,7 +284,7 @@ protected function doTestLanguageBlock404(string $block_label, string $system_pa
    $labels = [];
    foreach ($language_switchers as $list_item) {
      $list_items[] = [
        'hreflang' => $list_item->getAttribute('hreflang'),
        'data-drupal-language' => $list_item->getAttribute('data-drupal-language'),
        'data-drupal-link-system-path' => $list_item->getAttribute('data-drupal-link-system-path'),
      ];

@@ -296,8 +296,8 @@ protected function doTestLanguageBlock404(string $block_label, string $system_pa
      $labels[] = $link->getText();
    }
    $expected_list_items = [
      0 => ['hreflang' => 'en', 'data-drupal-link-system-path' => $system_path],
      1 => ['hreflang' => 'fr', 'data-drupal-link-system-path' => $system_path],
      0 => ['data-drupal-language' => 'en', 'data-drupal-link-system-path' => $system_path],
      1 => ['data-drupal-language' => 'fr', 'data-drupal-link-system-path' => $system_path],
    ];
    $this->assertSame($expected_list_items, $list_items, 'The list items have the correct attributes that will allow the drupal.active-link library to mark them as active.');
    $expected_anchors = [
+49 −43

File changed.

Preview size limit exceeded, changes collapsed.