Incompatibility with this hook_preprocess_links__language_block in .theme file

Created on 9 January 2025, 3 months ago

Problem/Motivation

Hello everyone,

Iโ€™ve encountered an incompatibility issue with the hook_preprocess_links__language_block inside the .theme file of my custom theme. I have three themes, and in two of them one being the siteโ€™s primary (default) theme and the other applied when a specific content type is used the hook works correctly.

However, when creating a third theme with the same structure and hooks as the previous ones, the hook_preprocess_links__language_block stops working. It seems that, for some reason, there is an incompatibility.

All of this has been tested on Drupal 10.3.6 and PHP 8.1.31.

Steps to reproduce

--

Proposed resolution

The potential solution has been to add the following function/hook inside a .module file, using a conditional for the active or specific theme where I want the logic to apply to alter the language names to their initials.

/**
* Use language code for the language switcher
*
* @param $vars
*/
function themename_preprocess_links__language_block(&$vars) {
    foreach ($vars['links'] as $i => $link) {
      $linkLanguage = $link['link']['#options']['language'];
      $vars['links'][$i]['link']['#title'] = $linkLanguage->get('id');
    }
}

Remaining tasks

--

User interface changes

--

API changes

--

Data model changes

--

๐Ÿ› Bug report
Status

Active

Version

2.1

Component

Code

Created by

๐Ÿ‡ช๐Ÿ‡ธSpain pau.sanz

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

Comments & Activities

Production build 0.71.5 2024