Unsubscribe link uses outdated 'langcode' option in Url::fromRoute(), resulting in incorrect language in generated URL

Created on 7 July 2025, 1 day ago

Problem/Motivation

The simplenews_generate_url() function currently builds unsubscribe links using the langcode option in the $options array passed to Url::fromRoute():

$url_arguments = ['absolute' => TRUE, 'langcode' => $subscriber->getLangcode()];
...
return Url::fromRoute("simplenews.subscriptions_$action", $route_parameters, $url_arguments)->toString();

The langcode key is not supported for generating translated URLs using Url::fromRoute(). The correct and recommended way is to use the language key and pass an instance of \Drupal\Core\Language\LanguageInterface.

Because of this, the unsubscribe link may not include the expected language prefix (e.g., /fr), and subscribers receive links in the default site language instead of their preferred language.

Steps to reproduce

  1. Create a user/subscriber with a language different from the site default (e.g., French).
  2. Send a Simplenews email to that subscriber.
  3. Observe the unsubscribe link in the email.
  4. The link does not include the correct language prefix (e.g., /fr) and is generated in the default language.

Proposed resolution

Use the right language key.

🐛 Bug report
Status

Active

Version

4.1

Component

Code

Created by

🇧🇷Brazil andre.bonon

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

Comments & Activities

Production build 0.71.5 2024