Incorporate Drupal 9.4 core changes to getLanguageSwitchLinks

Created on 22 March 2022, over 2 years ago
Updated 21 March 2023, over 1 year ago

Problem/Motivation

There is a wrong usage of the null coalescing operator in Line 147 of "src/Plugin/Block/DropdownLanguage.php":
$links = $this->languageManager->getLanguageSwitchLinks($derivative_id, Url::fromRoute($route)) ?? $this->languageManager->getLanguageSwitchLinks($derivative_id, Url::fromRoute($route))->links;

If "getLanguageSwitchLinks()" returns an object, the left-hand side of the argument is true and therefore returns the left handside of the argument as the value for $links.

But in further lines "$links" is treated as an array, which leads to the following error:

Error: Cannot use object of type stdClass as array in Drupal\dropdown_language\Plugin\Block\DropdownLanguage->build() (line 192 of modules/contrib/dropdown_language/src/Plugin/Block/DropdownLanguage.php).

Steps to reproduce

Proposed resolution

Instead, the Elvis Operator should be used here.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇳🇱Netherlands Ruuds

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