Warning: Undefined array key "#access" in language_form_alter()

Created on 2 June 2023, almost 2 years ago
Updated 12 September 2024, 7 months ago

Problem/Motivation

Sometimes $form[$langcode_key]['#access'] can be undefined and is better to check if it exists and not just if $form[$langcode_key] is defined.

Sometimes I get this error on my sites:
Warning: Undefined array key "#access" in language_form_alter() (line 370 of core/modules/language/language.module).

And with a simple validation, we can fix this.

Steps to reproduce

Is hard to say how this happens but I thin a better check on the if can fix this without any additional problems.

Proposed resolution

Change the validation from:

    if (isset($form[$langcode_key]) && $form[$langcode_key]['#access'] !== FALSE) {
      $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle($entity->getEntityTypeId(), $entity->bundle());
      $form[$langcode_key]['#access'] = $language_configuration->isLanguageAlterable();
    }

to:

    if (isset($form[$langcode_key]['#access']) && $form[$langcode_key]['#access'] !== FALSE) {
      $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle($entity->getEntityTypeId(), $entity->bundle());
      $form[$langcode_key]['#access'] = $language_configuration->isLanguageAlterable();
    }

Remaining tasks

Review the patch.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

None.

๐Ÿ› Bug report
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Language systemย  โ†’

Last updated about 2 hours ago

  • Maintained by
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany @sun
Created by

๐Ÿ‡จ๐Ÿ‡ฆCanada adriancid Montreal, Canada

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

Merge Requests

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