FormatterBase should set $element['#language'] to the passed-in langcode

Created on 11 January 2016, over 9 years ago
Updated 25 July 2025, 1 day ago

Problem/Motivation

FormatterBase sets a #language property on the element that it returns (which is - confusingly - not a language object, but a language code, but that aside). This is useful for alter hooks and preprocess functions. However, $element['#language'] does not correspond to the language code passed into FormatterInterface::view().

Proposed resolution

Line 98 of \Drupal\Core\Field\FormatterBase::view():

-        '#language' => $items->getLangcode(),
+        '#language' => $langcode,

Remaining tasks

<!-- See https://drupal.org/core-mentoring/novice-tasks for tips on identifying novice tasks. Delete or add "Novice" from the Novice? column in the table below as appropriate. Uncomment tasks as the issue advances. Update the Complete? column to indicate when they are done, and maybe reference the comment number where they were done. -->

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

field system

Created by

πŸ‡©πŸ‡ͺGermany tstoeckler Essen, Germany

Live updates comments and jobs are added and updated live.
  • D8MI

    (Drupal 8 Multilingual Initiative) is the tag used by the multilingual initiative to mark core issues (and some contributed module issues). For versions other than Drupal 8, use the i18n (Internationalization) tag on issues which involve or affect multilingual / multinational support. That is preferred over Translation.

  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

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.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for reporting this problem. We rely on issue reports like this one to resolve bugs and improve Drupal core.

    Since there has been no activity here for over 8 years we are asking if this problem persists on a currently supported version of Drupal. To help, add a comment explaining if the problem still occurs or not. Any extra detail you can provide can help others who experienced this.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
    Thanks!

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    This would be a BC break for anyone relying on it in the current state, we could go through the hoops of deprecating and changing it somehow but it doesn't seem like it's worth the effort.

Production build 0.71.5 2024