Undefined array key "description_field_required" in \Drupal\file\Plugin\Field\FieldWidget\FileWidget::formElement

Created on 10 August 2023, over 1 year ago

Problem/Motivation

In some scenarios, when editing an entity with a file field, the following warning appears:
Warning: Undefined array key "description_field_required" in /var/www/app/docroot/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php on line 249

Steps to reproduce

Not sure - we encountered this on taxonomy terms with file fields, which had been created before a Drupal core upgrade.

After saving the field settings, the warning did not appear.

Proposed resolution

tbc

Remaining tasks

User interface changes

none

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

10.1 ✨

Component
File moduleΒ  β†’

Last updated 9 days ago

Created by

πŸ‡¬πŸ‡§United Kingdom malcomio

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @malcomio
  • last update over 1 year ago
    29,459 pass
  • @malcomio opened merge request.
  • Status changed to Needs review over 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom malcomio

    The warning can be prevented with the change in https://git.drupalcode.org/project/drupal/-/merge_requests/4574, but I don't know if there are any other effects of this field not being set.

    I suspect that the proper fix may be in update hooks somewhere.

  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for reporting

    So typically with these kind of issues we need to determine why this key isn't set. Could be masking a large problem.

  • πŸ‡¬πŸ‡§United Kingdom stefank

    Hi all,

    Attaching a patch for D10 as well, in case anyone also needs it. Should apply cleanly using composer.

  • First commit to issue fork.
  • Merge request !10674Resolve #3380377 "Undefined array key 11.x" β†’ (Open) created by oily
  • πŸ‡¬πŸ‡§United Kingdom oily Greater London

    oily β†’ changed the visibility of the branch 3380377-undefined-array-key to hidden.

  • πŸ‡¬πŸ‡§United Kingdom oily Greater London

    Created new 11.x branch, hid old branch.

  • Pipeline finished with Success
    about 1 month ago
    Total: 314s
    #378203
  • Pipeline finished with Success
    about 1 month ago
    Total: 824s
    #378218
  • πŸ‡¬πŸ‡§United Kingdom oily Greater London

    I grepped 'description_field_required' in core and it does not exist. However the code in the related issue #2320877 adds a key named 'description_field_required'.

    @malcomio, Is it possible that whenever you encountered the warning message in the issue description that the site contained code that added that key. e.g. in a contributed module, composer patch or custom module?

    Logically the only other way (I can think of) that that key could appear purely as a result of core code would be if it is dynamically generated eg by concatenating a string with a string from a variable. Then grepping 'description_field_required' would return nothing.

    If the key is created outiside core eg in a contrib module then this is not a core issue and it can safely be closed.

Production build 0.71.5 2024