Add an API method to LanguageInterface to simply checking, if a language is a pseudo language

Created on 8 August 2023, over 1 year ago
Updated 15 November 2023, about 1 year ago

Problem/Motivation

Follow up issue for πŸ› Invalid argument exception when changing language of node with menu link to und or zxx Fixed , originally proposed there in comment #7 by @esolitos

In certain cases you need to check, if a language is a pseudo language (i.e. und or zxx). This is quite complicated:

if (!in_array($node->language()->getId(), [LanguageInterface::LANGCODE_NOT_APPLICABLE, LanguageInterface::LANGCODE_NOT_SPECIFIED], TRUE)) {
  // do something
}

For better DX, we should add a method to Drupal\Core\Language\LanguageInterface to simplify this check:

if (!$node->language()->newMethod()) {
  // do something
}

Steps to reproduce

n/a

Proposed resolution

tbd

Remaining tasks

  1. Decide on good method name.
  2. Implement changes to the interface.
  3. Write change record.

User interface changes

None.

API changes

New method to check, if a language is a pseudo language.

Data model changes

None.

Release notes snippet

tbd

✨ Feature request
Status

Closed: works as designed

Version

11.0 πŸ”₯

Component
Language systemΒ  β†’

Last updated about 15 hours ago

  • Maintained by
  • πŸ‡©πŸ‡ͺGermany @sun
Created by

πŸ‡©πŸ‡ͺGermany FeyP

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024