Warning if #access not defined on form

Created on 21 March 2022, over 2 years ago
Updated 10 October 2023, about 1 year ago

Problem/Motivation

This is a followup to #3017812: Language selector is immune to hook_entity_field_access in entity forms. .

This if statement in language.module was throwing warnings when i form i had didn't have #access set inside $form['langcode'].

    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();
    }

From comment #13 of the original issue.

Steps to reproduce

TBA

Proposed resolution

Add a check that #access is set.

Remaining tasks

Patch, review,commit

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

🐛 Bug report
Status

Needs work

Version

10.0

Component
Language module 

Last updated 24 days ago

  • Maintained by
  • 🇩🇪Germany @sun
Created by

🇳🇿New Zealand quietone

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

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇦🇺Australia amjad1233 Brisbane

    Hi @quietone,

    +    if (isset($form[$langcode_key]) && (!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();
         }
    

    Looks good. In your experience with the patch, is it easy to add a test?

  • Status changed to Needs review about 1 year ago
  • last update about 1 year ago
    29,654 pass
  • 🇮🇳India priya.chat

    Hi @quietone,

    Thanks for the patch, I have made a change in the patch #3.

  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States smustgrave

    Was previously tagged for tests. Also may need to backtrace why that value is not defined. Usually putting an empty or isset check could be masking a larger option.

Production build 0.71.5 2024