Missing config is not handled early enough

Created on 15 November 2022, almost 2 years ago
Updated 28 March 2024, 5 months ago

Problem/Motivation

If required config values are not set, errors will occur later on and are difficult to trace. For example, if $field_prefix is not set, then:

modules/field_ui/src/Form/FieldStorageAddForm.php
'#maxlength' => FieldStorageConfig::NAME_MAX_LENGTH - strlen($field_prefix),

will fail when NULL to strlen.

Proposed resolution

From comments #11 and #13

>>> \Drupal::config('some_module.non_existent')
=> Drupal\Core\Config\ImmutableConfig {#6251}

Should this throw an exception instead, and we need a separate explicit call to create a new config? This would warn users earlier that expected config is missing.

>>> \Drupal::config('field_ui.settings')->get('non_existent_key')
=> null

Maybe also this should throw an exception, if the config exists but the key does not, instead of falling back to NULL?

Remaining tasks

  1. Agree on an approach. Per #14, the proposed solution would require a deprecation first. But per #15 there are other things to consider.
  2. Write a patch with tests
  3. Review
  4. Commit

User interface changes

N/A

API changes

TBC

Data model changes

TBC

Release notes snippet

TBC

Original report by [username]

I had the case that $field_prefix was not set and therefore I got the issue with passing NULL to strlen.

modules/field_ui/src/Form/FieldStorageAddForm.php
'#maxlength' => FieldStorageConfig::NAME_MAX_LENGTH - strlen($field_prefix),
🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Field UI 

Last updated 5 days ago

Created by

🇨🇭Switzerland unkelhoebbi

Live updates comments and jobs are added and updated live.
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.

Production build 0.71.5 2024