From 04c69d52c839443c4e47ae009e9df32d000348ae Mon Sep 17 00:00:00 2001
From: David Cameron <david@cadeyrn.us>
Date: Sun, 16 Mar 2025 15:12:47 -0500
Subject: [PATCH] Remove the language block navigation role

---
 core/modules/language/language.module         |  9 --------
 .../src/Functional/LanguageSwitchingTest.php  | 21 +++++++++++++++++++
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/core/modules/language/language.module b/core/modules/language/language.module
index dba38c258990..fb2bfdc9c2ef 100644
--- a/core/modules/language/language.module
+++ b/core/modules/language/language.module
@@ -126,15 +126,6 @@ function language_negotiation_url_prefixes_update() {
   $config->set('url.prefixes', $prefixes)->save(TRUE);
 }
 
-/**
- * Implements hook_preprocess_HOOK() for block templates.
- */
-function language_preprocess_block(&$variables): void {
-  if ($variables['configuration']['provider'] == 'language') {
-    $variables['attributes']['role'] = 'navigation';
-  }
-}
-
 /**
  * Returns language mappings between browser and Drupal language codes.
  *
diff --git a/core/modules/language/tests/src/Functional/LanguageSwitchingTest.php b/core/modules/language/tests/src/Functional/LanguageSwitchingTest.php
index 32ec3a2c6e51..b6001f2be79d 100644
--- a/core/modules/language/tests/src/Functional/LanguageSwitchingTest.php
+++ b/core/modules/language/tests/src/Functional/LanguageSwitchingTest.php
@@ -84,6 +84,7 @@ public function testLanguageBlock(): void {
     ]);
 
     $this->doTestLanguageBlockAuthenticated($block->label());
+    $this->doTestLanguageBlockRole($block->label());
     $this->doTestHomePageLinks($block->label());
     $this->doTestLanguageBlockAnonymous($block->label());
     $this->doTestLanguageBlock404($block->label(), 'system/404');
@@ -211,6 +212,26 @@ protected function doTestLanguageBlockAuthenticated($block_label): void {
     $this->assertSame(['English', 'français'], $labels, 'The language links labels are in their own language on the language switcher block.');
   }
 
+  /**
+   * Verifies that the block does not have the navigation role attribute.
+   *
+   * @param string $block_label
+   *   The label of the language switching block.
+   *
+   * @see self::testLanguageBlock()
+   */
+  protected function doTestLanguageBlockRole($block_label): void {
+    // Assert that the language switching block is displayed on the frontpage.
+    $this->drupalGet('');
+    $this->assertSession()->pageTextContains($block_label);
+
+    $block = $this->xpath('//div[@id=:id][not(@role=:role)]', [
+      ':id' => 'block-test-language-block',
+      ':role' => 'navigation',
+    ]);
+    $this->assertCount(1, $block);
+  }
+
   /**
    * For anonymous users, the "active" class is set by PHP.
    *
-- 
GitLab