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

CommentFileSizeAuthor
#6 3380377-D10-6.patch888 bytesstefank

Issue fork drupal-3380377

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

malcomio created an issue. See original summary.

malcomio’s picture

Status: Active » Needs review

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.

It may relate to #2320877: Add a setting to make description a required field for file items - that was the only other mention of this that I found

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs steps to reproduce, +Needs tests

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.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

stefank’s picture

StatusFileSize
new888 bytes

Hi all,

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

oily made their first commit to this issue’s fork.

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

oily’s picture

Created new 11.x branch, hid old branch.

oily’s picture

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'. You can see it added in the code here.

@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.

mohit_aghera’s picture

Status: Needs work » Postponed (maintainer needs more info)

I was trying to reproduce the issue and had no luck.

I tried following instances.
- In core check if there are any concatenated fields like "description_field_required"
Initially I did a quick search to see if we have dynamic variable. i.e. grep -r "_required'" core/
This didn't yielded any results.

Later I did same search with prefix i.e. "description_".
This didn't returned anything either.

My only guess is that if the patch from https://www.drupal.org/project/drupal/issues/2320877 issue is applied to core.
In-case it is not applied cleanly then $field_settings might not have key "description_field_required"
Reason is that, the error appears on line 249 which is close to the change in the above PR.

Another reason can be that above patch is used and update hook isn't called.
There is a "file_post_update_description_required()" which sets the values.
To confirm that there is a dedicated update test as well https://git.drupalcode.org/project/drupal/-/merge_requests/5876/diffs#di... which checks that "description_field_required" doesn't exist before update hook and it exists after update hook.

Apart from that I am in favour of postponing the issue unless we have clear steps to reproduce.

Please reopen again if you feel it is happening again with majority of users with the vanilla core.

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)
Issue tags: +Bug Smash Initiative

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.