Problem/Motivation
A site builder is able to allow the user to enter a description for the file field upload. However, in some circumstances, the description may be mandatory. Right now there's no way for a site builder to make the file field upload description mandatory.
Proposed resolution
Add a new setting for file items to require the file description.
Remaining tasks
Updated 5/23/23
See #85
- Framework manager review
- Add JavaScript test coverage for #states that support the progressive disclosure
- Manual testing
- Update the upgrade path tests. Is this addressed by f0a74cb? Or is there more work to do here?
- Add REST/JSON:API test coverage
- Question from manual testing in #100: If the description field is required for a media item, should it be available on file upload when you have a Media field?
User interface changes
A new file field setting that allows to enforce the description.
Site builder perspective

End-user perspective

API changes
None.
Data model changes
New, description_field_required, boolean key in the mapping of code>field.field_settings.file schema.
Release notes snippet
As a site builder, on a file field settings form, after checking Enable Description field, check the Require the Description field setting in order to make the file upload required.
Original report
If I add a file field and check Description, I don't get the option to make Description a required field. This results in the public seeing often-unfriendly file names instead of a meaningful description.
Steps: As admin:
1. Edit basic page
2. Add new file field
Actual result: Description is not prechecked
Expected result: Optionally, Description is pre-checked as the public-friendliest solution
3. Check Description
Actual result: No option to require description appears
Expected result: Check box to require description appears. Optionally, it is pre-checked as the public-friendliest solution.
As editor:
1. Add new basic page
2. Attach file
3. Don't fill in Description field
4. Save and publish
Actual result: No error
Expected result: Error
| Comment | File | Size | Author |
|---|---|---|---|
| #141 | 2320877-nr-bot.txt | 91 bytes | needs-review-queue-bot |
Issue fork drupal-2320877
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:
- 2320877-description-required-11.x
changes, plain diff MR !5876
- 2320877-10.5
changes, plain diff MR !12421
- 2320877-10.4
changes, plain diff MR !11921
- 2320877-description-required-10.0.x
changes, plain diff MR !4255
- 2320877-10.1.x
changes, plain diff MR !3915
- 10.1.x
compare
- 2320877-9.5
changes, plain diff MR !3117
- 2320877-9.4.x
changes, plain diff MR !2529
- 2320877-9.3.x
changes, plain diff MR !975
- 2320877-description-required
changes, plain diff MR !282
Comments
Comment #4
pfrenssenThis is a very good suggestion. Thanks also for the excellently written feature request.
I would propose to default to _not_ requiring the description field. That will make it fully backwards compatible with the current implementation and we won't need to create an update path.
Assigning to me to make a first draft of this feature request.
Comment #5
pfrenssenHere is a proposed implementation.
Comment #7
pfrenssenAnd I though I finally understood schema definitions, nope.
Comment #9
pfrenssenMore test fixes.
Comment #11
pfrenssenFixed a coding standards violation, and hopefully also the installer test, I didn't try to run this locally.
Comment #12
pfrenssenSmall improvement: the image field extends the file field but has its own "title" field that replaces the description. The
description_field_requiredconfiguration parameter is not used by the image field so we should unset it.Comment #14
pfrenssenFixed the new installer error as well as a notice that occurs when submitting a form containing a required description on a non-required file field and not populating the file field:
Comment #15
pfrenssenJust discovered that this now prevents the removal of a file, or replacing a file with another with the validation error "Description field is required".
Comment #16
pfrenssenSkipped the validation when uploading or removing files. I first tried to do this via
#limit_validation_errorsinFileWidget::process()but this wasn't really feasible, since we would need to limit validation errors on the whole file field _except_ the description child element. There is no#skip_validation_errorsto selectively skip validation for a particular element.Also fixed the other install error.
Comment #18
mahalingam_cs commentedPatch 2320877-16.patch failed to apply. Can you check and update with the new patch
Comment #19
mahalingam_cs commentedComment #20
harsha012 commentedre-rolled the patch to 8.5.x
Comment #22
mahalingam_cs commentedPatch form #20 applied successfully. But,
- The Description is not pre-checked as the public-friendliest solution
- When the "Enable Description field" is checked , "Require the Description field" option displays which is working as expected.
Comment #23
pfrenssenThis would break backwards compatibility with the current implementation.
Comment #26
claudiu.cristeaStraight reroll of #16.
Comment #28
claudiu.cristeaFixed the tests. Also reverted the change from #7 because
description_field_requiredis only part of the file schema, together withdescription_field.Comment #31
claudiu.cristeaReroll for 8.8.x
Comment #32
claudiu.cristeaAdding a new config key needs an update path, right?
According to
field.field_settings.fileschema this should be a boolean, not integer.This is wrong. It should default to
FALSE, not"", as is a boolean. But we don't need the ternary operator because we're covered with sane defaults.All should
FALSE. See their default settings.Let's modernize: s/get_class($this)/static::class
!array_diff() ?
Try to compact in a single line.
Comment #33
claudiu.cristeaFixes #32.
Comment #35
claudiu.cristeaHm, as
ImageItemis extendingFileItem, we still have to keep the check on settings existence as these default settings are removed inImageItem::defaultFieldSettings().. But this time we're setting the correct type, which is boolean. Also, we should remove the new setting form element fromImageItem.Comment #36
claudiu.cristeaComment #37
pfrenssenChanges look good to me but I cannot RTBC this since I made the initial implementation and this was not RTBC before.
Comment #40
mrpauldriver commentedThis patch solves a common problem for document heavy Drupal sites.
Tested against core versions 8.9.9 and 9.0.9. Patch applies without any problems.
As well as generic files, this works with the media library and media library modal. It is also filterable in the media library if the
field_media_file_descriptionidentifier is used.This also solves problems that the media module creates, because the inconsistency of how the media name base field is generated when uploading files directly to the media library versus via the media library modal. This inconsistency also results "in the public (and editors) seeing often-unfriendly file names instead of a meaningful description".
Please commit. This should have been in core ten years ago :-)
Comment #41
claudiu.cristeaYou cannot RTBC a patch that is not passing the test. Most probably the patch needs a reroll against 9.2.x
Comment #42
mrpauldriver commentedThank you for correcting me.
Is this something you could look at @claudiu.cristea ?
Comment #43
anushrikumari commentedComment #44
anushrikumari commentedRerolled patch #35 for 9.2.x
Comment #45
claudiu.cristeaThis was once RTBCed, in #40. I’m only setting back after reroll.
Comment #46
mrpauldriver commentedI am finding that patch #44 does not apply with composer.
Comment #47
claudiu.cristeaProbably you’re not on 9.2.x. If applies in #45, then it works also with Composer.
Comment #48
alexpottWe need a change record for this change.
This patch has some coding standards issues.
Comment #49
claudiu.cristeaAdded change record. Fixed minor code standards issues.
Comment #50
alexpottComment #51
claudiu.cristeaReverting a too far change.
Comment #52
alexpottAdded the issue summary template. It could do with being properly completed.
Comment #53
claudiu.cristeaUpdated the IS according to template.
Comment #54
xjmThanks for your work on this issue! I've a couple questions about it:
Tagging for usability review to (a) Help decide where the usability gain offsets the cost and (b) Review the UI change itself.
Also, one improvement that I think we don't even need a usability team review to make:
This description is redundant with the label and should be removed. Our guidance for form elements is that, where possible, descriptions should be omitted in favor of including all relevant info in the label. The label by itself is already sufficient here.
You can get additional feedback for usability by joining the
#uxchannel in Drupal Slack, and in particular from the weekly UX meeting Fridays at 1500 UTC.Comment #55
xjmUnrelatedly, this is sort of false:
Additions to the config schemata are data model additions and should probably be documented there in the IS.
Comment #56
alexpottI think in order to do this so that the required-ness also works for JsonAPI and on entity validation we need to implement a \Drupal\file\Plugin\Field\FieldType\FileItem::getConstraints() and add a constraint on the field to check that the description is not empty.
Comment #57
alexpottIf #56 is done then this code should be obsolete.
This changes of value are a bit odd - why is this being done here apart from for "consistency"?
Comment #58
mrpauldriver commentedHas anyone had chance to do further work on this?
Comment #60
claudiu.cristea@xjm
title_field_requiredfrom image item. And if that exists in core and is exposed in UI, I see no reason why this one shouldn't be.@alexpott
Ready for another review.
Comment #61
claudiu.cristeaTo whom it may concern: here's an 8.9.x unofficial version. This patch is not for review.
Comment #62
pfrenssenI found a few nitpicks but apart from these this is looking good. I think this probably fine from a usability perspective since this functionality is similar to what we have in image fields. Anyway let's keep the usability review tag so this can be discussed at the UX meeting.
Comment #63
benjifisherUsability review
We discussed this issue at #3200598: Drupal Usability Meeting 2021-02-26.
From #54:
Without doing any surveys nor user testing we are just guessing, but the consensus is that this feature will be popular enough that it is worth adding to core. Part of that opinion is that a hypothetical contrib module that just provides this change would be hard to discover. I know that @phenaproxima has suggested Media Library Extras as a home for such little tweaks, but since this issue is concerned with file fields, which may or may not be attached to media, that does not seem appropriate.
We did not discuss the second question at the meeting. My personal opinion is that the "Require the Description field" checkbox should be exposed only when "Enable Description field" is checked (progressive disclosure). I think the current patch already works this way. Given that, there is no extra clutter by default, and the additional field is exposed at exactly the right time.
Comment #64
mrpauldriver commentedGood to see this was endorsed by the UX group.
Is there anything to prevent this finding it's way in the core?
Comment #65
claudiu.cristeaFixed MR remarks from @pfrenssen.
@MrPaulDriver, the best way to get this in core, is to help test the latest MR version and do a code review. Then, if satisfied, to mark as RTBC.
Comment #66
mrpauldriver commentedSorry. Not up to speed with the new MR workflow.
Comment #67
Madhu kumar commentedCan't apply patch #44 on 9.2.x , added screenshot for the reference.
Comment #68
claudiu.cristea@MrPaulDriver, that's very simple:
composer.jsonwhich is the MR URL followed by.diffextension. In this case you should append.difftohttps://git.drupalcode.org/project/drupal/-/merge_requests/282, so your patch will be https://git.drupalcode.org/project/drupal/-/merge_requests/282.diffComment #69
claudiu.cristea@Madhu kumar, #44 is outdated, the 9.2 code is in MR. Please don't post anymore the screenshots, they are useless and only clutters the issue. We can determine if a patch applies by running the tests.
Comment #71
scoisne commentedHello, i may be dumb but the MR !282 don't seems to be a valid patch for the 9.2.0 even if the test are correct.
I'm trying to apply with composer with no luck so far.
I'm trying on a fresh D9 install (with only cweagans/composer-patches for applying patches)
I'm missing something ?
Comment #72
guillaumeg commentedMerging latest 9.2.x branch from drupal repo and fixing conflits.
Ready to review / test.
GuillaumeG made their first commit to this issue’s fork.
Comment #73
anweshasinha commentedI am working in this
Comment #74
anweshasinha commentedHi,
I have worked on this. Please review my work.
Comment #75
anweshasinha commentedComment #76
anweshasinha commentedMade certain changes in the patch. The updated one is given below.
Comment #77
ranjith_kumar_k_u commentedFixed custom command failure
Comment #78
aaronmchaleSince a merge request has been opened for this issue and has commits, please use that for adding changes/fixes instead of uploading patch files, otherwise we'll just end up with multiple branching versions of this and so wasted effort, thank you.
Comment #79
paulocsThe MR should be actually merged into 9.3.x branch.
Comment #81
paulocsI was not able to close the MR 282. I created a new branch and opened a new MR into the 9.3.x Drupal branch.
Comment #82
marcusvsouza commentedThe MR in comment #80 works as expected, implemented in all types of media content with no code standards problems.
Image attached for reference.
Comment #83
marcusvsouza commentedChanging to RTBC!
Comment #85
xjmRemoving credit for unnecessary patches and screenshots.
Sorry that this issue has sat for so long without feedback. Given that I missed #56 I would prefer a framework manager review the issue again prior to commit.
#63 seems reasonable; thanks @benjifisher and UX team.
#statesuse present that presumably supports the progressive disclosure, but not JavaScript test coverage for the behavior. We should add that.Thanks everyone!
Comment #86
xjmAlso adding credit for helpful reviews. Thanks, reviewers!
Comment #90
megadesk3000 commentedHello together
Thanks for your work so far.
MR !975 was not applying against 9.4.3, so i rebased the changes on 9.4.x.
Comment #93
szato commentedUsing MR#3117 with 9.5.7, works. Thank you.
Comment #94
florianmuellerchAs this affects core and I have the need to apply multiple patches, I created a patch for 10.x to apply.
Comment #97
capysara commentedRe-rolled for 10.1.x. I based this MR on MR#3117 because the patch in the previous comment introduced some changes from the last version, most notably removing the constraints that were added in a previous commit. Maybe the patch was based on an earlier version?
I did not make any changes to the re-roll, so the updates noted in #85 still need to be implemented. I'm working on manually testing it.
Comment #98
capysara commentedComment #100
capysara commentedManual testing (WIP)
I used the Live preview via Tugboat (TIL there's a Live preview via Tugboat!)
Not good* Can't save because I didn't add a description to myfile1. When I added the field, I Enabled description, enabled Require, and then Disabled description, but didn't disable Require. Now it's expecting a value, but the Description field doesn't display.Same behavior with other entities tested: Block (Basic), User, and Media (types Document and Video).
UPDATE: pushed a new commit to disable the description_field_required if description_field is not enabled, which fixes it.
Comment #101
capysara commentedComment #104
malcomio commentedWith the patch from #94 applied, we have observed PHP warnings, similar to #3380377: Undefined array key "description_field_required" in \Drupal\file\Plugin\Field\FieldWidget\FileWidget::formElement:
Undefined array key "description_field" in \Drupal\file\Plugin\Field\FieldWidget\FileWidget::formElementComment #105
vanitha sophia commentedTo address the Undefined array key "description_field" in \Drupal\file\Plugin\Field\FieldWidget\FileWidget::formElement for issue 104, we can use this patch
Comment #106
guardiola86 commentedTested and it's working fine
Comment #107
poker10 commented@guardiola86 Thanks for your review and the status change, but this issue should be a Needs Work at the moment.
Which patch/MR have you reviewed? If the one from #105, this patch does not apply. The bigger issue is, that the content of that patch is significantly different from the MR 3915 and MR 4255 (see for example the default label "Require Description field"). Therefore I am not sure what was the starting point for this patch. Also the patch is missing interdiff, so we are unable to see what changes were made.
It is good to use MRs in case these are already created and not to upload new patches.
@Vanitha Sophia Thanks for working on this issue, but at the start I suggest to read this contributor guide: https://www.drupal.org/community/contributor-guide/task/create-a-patch-f... before adding another patches here.
Comment #109
claudiu.cristeaComment #110
poker10 commentedThere is a failure in the MR pipeline, which does not looks like a random one, but related to the MR changes:
https://git.drupalcode.org/issue/drupal-2320877/-/jobs/507087
Comment #114
claudiu.cristeaTests are green. Ready for a final review.
Comment #115
claudiu.cristeaDrupal 10.3.x version patch
Comment #116
carolpettirossi commentedI tested the patch provided on #115 on Drupal 10.3.0, and it worked as expected. See below the test steps I executed:
Comment #117
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #118
claudiu.cristeaManual testing has been performed in #100
Comment #119
claudiu.cristeaTrying to revive this
Comment #126
claudiu.cristeaMR !5876 is for 11.x and review.
Comment #128
charles belovAlas, I could not apply the patch.
simplytest.me gives the following errors:
This may be the error:
[warning] Drush command terminated abnormally.
Command Failed (Tugboat Error 1064): Exit code: 1; Command: cd "${DOCROOT}" && ../vendor/bin/drush si standard --db-url=mysql://tugboat:tugboat@mysql:3306/tugboat --account-name=admin --account-pass=admin -y
Doing a file compare between a successful simplytest.me (Drupal core 11.x dev only) and my attempt to include this patch on Drupal core 11.x dev gave the following notable differences in the simplytest.me log, from the patch attempt:
09447f901e195c35cd0dee# /bin/sh -c composer global config --no-interaction allow-plugins.szeidler/composer-patches-cli true
Changed current directory to /root/.config/composer
6809447f901e195c35cd0dee# /bin/sh -c composer global config --no-interaction allow-plugins.cweagans/composer-patches true
Changed current directory to /root/.config/composer
6809447f901e195c35cd0dee# /bin/sh -c composer global require szeidler/composer-patches-cli:~1.0
Changed current directory to /root/.config/composer
./composer.json has been updated
Running composer update szeidler/composer-patches-cli
Loading composer repositories with package information
Updating dependencies
Lock file operations: 2 installs, 0 updates, 0 removals
- Locking cweagans/composer-patches (1.7.3)
- Locking szeidler/composer-patches-cli (1.0.8)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
- Downloading cweagans/composer-patches (1.7.3)
- Downloading szeidler/composer-patches-cli (1.0.8)
0/2 [>---------------------------] 0%
1/2 [==============>-------------] 50%
2/2 [============================] 100%
- Installing cweagans/composer-patches (1.7.3): Extracting archive
- Installing szeidler/composer-patches-cli (1.0.8): Extracting archive
Generating autoload files
No security vulnerability advisories found.
6809447f901e195c35cd0dee# /bin/sh -c cd stm && composer patch-enable --file="patches.json"
The composer patches file was created.
The composer patches functionality was enabled successfully.
6809447f901e195c35cd0dee# /bin/sh -c cd stm && composer patch-add drupal/core "STM patch 5876.patch" "https://git.drupalcode.org/project/drupal/-/merge_requests/5876.patch" --no-update
Gathering patches from patch file.
The patch was successfully added.
6809447f901e195c35cd0dee# /bin/sh -c cd stm && composer update --no-ansi
Gathering patches from patch file.
(later)
- Applying patches for drupal/core
https://git.drupalcode.org/project/drupal/-/merge_requests/5876.patch (STM patch 5876.patch)
Could not apply patch! Skipping. The error was: Cannot apply patch https://git.drupalcode.org/project/drupal/-/merge_requests/5876.patch
(later)
Fatal error: Cannot use Drupal\Core\Config\Entity\ConfigEntityUpdater as ConfigEntityUpdater because the name is already in use in /var/lib/tugboat/stm/web/core/modules/file/file.post_update.php on line 12
[warning] Drush command terminated abnormally.
Command Failed (Tugboat Error 1064): Exit code: 1; Command: cd "${DOCROOT}" && ../vendor/bin/drush si standard --db-url=mysql://tugboat:tugboat@mysql:3306/tugboat --account-name=admin --account-pass=admin -y
6809447f539fecb43c9c5a94 (simplytest) is suspended
Comment #129
claudiu.cristeaYou should use MR 5876 for 11.x
Comment #130
charles belovI thought that's what I did when I specified Drupal core 11.x and a patch of https://git.drupalcode.org/project/drupal/-/merge_requests/5876.patch
Is there some other URL I need to use to apply the patch?
Comment #131
ressa@charles belov: I just tried with the patch and Drupal 11.x-dev which worked well, and I see the new "Require the Description field" option. Maybe simplytest.me was temporarily challenged?
Comment #132
charles belovInteresting. 11.x-dev still fails for me but 11.1.x-dev works. Tested with 11.1.x-dev on simplytest.me.
Tested:
All work for me.
Comment #133
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #134
mohit_aghera commentedMoving to needs review since "needs-review-queue-bot" falsely made it to needs work
PR is green and it contains all the necessary tests.
Comment #135
mohit_aghera commentedComment #138
claudiu.cristeaComment #141
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #146
macsim commentedRebased MR !5876 on
mainbranch since the target branch changed in #143.Had to
core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.phpsince the file doesn't exist anymore on the target branchcore/modules/file/file.post_update.phpandcore/modules/file/src/Plugin/Field/FieldWidget/FileWidget.phpComment #147
macsim commentedComment #148
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #149
macsim commentedComment #150
smustgrave commentedAppears to need a rebase please
Comment #151
macsim commentedRebase done