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

  1. Framework manager review
  2. Add JavaScript test coverage for #states that support the progressive disclosure
  3. Manual testing
  4. Update the upgrade path tests. Is this addressed by f0a74cb? Or is there more work to do here?
  5. Add REST/JSON:API test coverage
  6. 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

CommentFileSizeAuthor
#105 2320877-105.patch5.64 KBVanitha Sophia
#94 2320877-94.patch5.53 KBflorianmuellerCH
#82 after_patch.png30.68 KBmarcusvsouza
#77 2320877-77.patch5.5 KBranjith_kumar_k_u
#76 2320877-76.patch5.52 KBanweshasinha
#75 2320877-74.patch5.52 KBanweshasinha
#74 download_required_1.png145.42 KBanweshasinha
#74 download_required_0.png162.29 KBanweshasinha
#74 2320877-68.patch5.52 KBanweshasinha
#67 applying-patch-file.png118.88 KBMadhu kumar
#61 2320877-61-unofficial-8.9.x.patch19.43 KBclaudiu.cristea
#60 widget.png84.25 KBclaudiu.cristea
#60 settings.png182.69 KBclaudiu.cristea
#51 2320877-51.patch14.64 KBclaudiu.cristea
#51 2320877-51.interdiff.txt1.29 KBclaudiu.cristea
#49 2320877-49.patch14.63 KBclaudiu.cristea
#49 2320877-49.interdiff.txt4.02 KBclaudiu.cristea
#44 2320877_44.patch14.73 KBanushrikumari
#35 2320877-35.patch14.77 KBclaudiu.cristea
#35 2320877-35.interdiff.txt2.05 KBclaudiu.cristea
#33 2320877-33.patch14.28 KBclaudiu.cristea
#33 2320877-33.interdiff.txt6.54 KBclaudiu.cristea
#31 2320877-31-8.8.x.patch11.15 KBclaudiu.cristea
#28 2320877-28.interdiff.txt5.78 KBclaudiu.cristea
#28 2320877-28.patch11.08 KBclaudiu.cristea
#26 2320877-26.patch7.55 KBclaudiu.cristea
#22 Not-Prechecked.png91.05 KBmahalingam_cs
#22 Required_Field.png93.63 KBmahalingam_cs
#20 2320877-20.patch7.45 KBharsha012
#16 interdiff.txt1.83 KBpfrenssen
#16 2320877-16.patch7.49 KBpfrenssen
#14 interdiff.txt1.4 KBpfrenssen
#14 2320877-14.patch7.59 KBpfrenssen
#12 interdiff.txt539 bytespfrenssen
#12 2320877-12.patch8.11 KBpfrenssen
#11 interdiff.txt2.12 KBpfrenssen
#11 2320877-11.patch7.58 KBpfrenssen
#9 interdiff.txt1.28 KBpfrenssen
#9 2320877-9.patch6.45 KBpfrenssen
#7 interdiff.txt832 bytespfrenssen
#7 2320877-7.patch5.77 KBpfrenssen
#5 2320877-5.patch5.76 KBpfrenssen

Issue fork drupal-2320877

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

pfrenssen’s picture

Assigned: Unassigned » pfrenssen

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

pfrenssen’s picture

Version: 8.3.x-dev » 8.4.x-dev
Assigned: pfrenssen » Unassigned
Status: Active » Needs review
FileSize
5.76 KB

Here is a proposed implementation.

Status: Needs review » Needs work

The last submitted patch, 5: 2320877-5.patch, failed testing.

pfrenssen’s picture

Status: Needs work » Needs review
FileSize
5.77 KB
832 bytes

And I though I finally understood schema definitions, nope.

Status: Needs review » Needs work

The last submitted patch, 7: 2320877-7.patch, failed testing.

pfrenssen’s picture

Status: Needs work » Needs review
FileSize
6.45 KB
1.28 KB

More test fixes.

Status: Needs review » Needs work

The last submitted patch, 9: 2320877-9.patch, failed testing.

pfrenssen’s picture

Status: Needs work » Needs review
FileSize
7.58 KB
2.12 KB

Fixed a coding standards violation, and hopefully also the installer test, I didn't try to run this locally.

pfrenssen’s picture

FileSize
8.11 KB
539 bytes

Small improvement: the image field extends the file field but has its own "title" field that replaces the description. The description_field_required configuration parameter is not used by the image field so we should unset it.

Status: Needs review » Needs work

The last submitted patch, 12: 2320877-12.patch, failed testing.

pfrenssen’s picture

Status: Needs work » Needs review
FileSize
7.59 KB
1.4 KB

Fixed 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:

Notice: Undefined index: description in Drupal\file\Plugin\Field\FieldWidget\FileWidget::validateRequiredDescription()

pfrenssen’s picture

Status: Needs review » Needs work

Just discovered that this now prevents the removal of a file, or replacing a file with another with the validation error "Description field is required".

pfrenssen’s picture

Status: Needs work » Needs review
FileSize
7.49 KB
1.83 KB

Skipped the validation when uploading or removing files. I first tried to do this via #limit_validation_errors in FileWidget::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_errors to selectively skip validation for a particular element.

Also fixed the other install error.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mahalingam_cs’s picture

Patch 2320877-16.patch failed to apply. Can you check and update with the new patch

mahalingam_cs’s picture

Status: Needs review » Needs work
harsha012’s picture

Status: Needs work » Needs review
FileSize
7.45 KB

re-rolled the patch to 8.5.x

Status: Needs review » Needs work

The last submitted patch, 20: 2320877-20.patch, failed testing. View results

mahalingam_cs’s picture

FileSize
93.63 KB
91.05 KB

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

pfrenssen’s picture

The Description is not pre-checked as the public-friendliest solution

This would break backwards compatibility with the current implementation.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
7.55 KB

Straight reroll of #16.

Status: Needs review » Needs work

The last submitted patch, 26: 2320877-26.patch, failed testing. View results

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
11.08 KB
5.78 KB

Fixed the tests. Also reverted the change from #7 because description_field_required is only part of the file schema, together with description_field.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

claudiu.cristea’s picture

claudiu.cristea’s picture

Assigned: Unassigned » claudiu.cristea
Status: Needs review » Needs work
  1. +++ b/core/modules/file/config/schema/file.schema.yml
    @@ -69,6 +69,9 @@ field.field_settings.file:
    +    description_field_required:
    

    Adding a new config key needs an update path, right?

  2. +++ b/core/modules/file/src/Plugin/Field/FieldType/FileItem.php
    @@ -51,6 +51,7 @@ public static function defaultFieldSettings() {
           'description_field' => 0,
    

    According to field.field_settings.file schema this should be a boolean, not integer.

  3. +++ b/core/modules/file/src/Plugin/Field/FieldType/FileItem.php
    @@ -193,6 +194,19 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
    +      '#default_value' => isset($settings['description_field_required']) ? $settings['description_field_required'] : '',
    

    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.

  4. +++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php
    @@ -214,6 +214,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
           'display_default' => NULL,
           'display_field' => NULL,
           'description_field' => NULL,
    +      'description_field_required' => NULL,
    

    All should FALSE. See their default settings.

  5. +++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php
    @@ -267,6 +269,9 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    +      $element['#element_validate'][] = [get_class($this), 'validateRequiredDescription'];
    

    Let's modernize: s/get_class($this)/static::class

  6. +++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php
    @@ -333,6 +338,33 @@ public static function value($element, $input, FormStateInterface $form_state) {
    +    if (array_diff($parent, array_intersect($parent, $trigger_parents)) === []) {
    

    !array_diff() ?

  7. +++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php
    @@ -333,6 +338,33 @@ public static function value($element, $input, FormStateInterface $form_state) {
    +    // Throw a validation error if a file is present but the description is
    +    // empty.
    

    Try to compact in a single line.

claudiu.cristea’s picture

Status: Needs review » Needs work

The last submitted patch, 33: 2320877-33.patch, failed testing. View results

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
2.05 KB
14.77 KB

Hm, as ImageItem is extending FileItem, we still have to keep the check on settings existence as these default settings are removed in ImageItem::defaultFieldSettings().. But this time we're setting the correct type, which is boolean. Also, we should remove the new setting form element from ImageItem.

claudiu.cristea’s picture

Assigned: claudiu.cristea » Unassigned
pfrenssen’s picture

Changes look good to me but I cannot RTBC this since I made the initial implementation and this was not RTBC before.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

MrPaulDriver’s picture

Status: Needs review » Reviewed & tested by the community

This 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_description identifier 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 :-)

claudiu.cristea’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

You cannot RTBC a patch that is not passing the test. Most probably the patch needs a reroll against 9.2.x

MrPaulDriver’s picture

Thank you for correcting me.

Is this something you could look at @claudiu.cristea ?

anushrikumari’s picture

Assigned: Unassigned » anushrikumari
anushrikumari’s picture

Assigned: anushrikumari » Unassigned
Status: Needs work » Needs review
FileSize
14.73 KB

Rerolled patch #35 for 9.2.x

claudiu.cristea’s picture

Status: Needs review » Reviewed & tested by the community

This was once RTBCed, in #40. I’m only setting back after reroll.

MrPaulDriver’s picture

Status: Reviewed & tested by the community » Needs work

I am finding that patch #44 does not apply with composer.

claudiu.cristea’s picture

Status: Needs work » Reviewed & tested by the community

Probably you’re not on 9.2.x. If applies in #45, then it works also with Composer.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs reroll +Needs change record

We need a change record for this change.

This patch has some coding standards issues.

FILE: /Users/alex/dev/drupal/core/modules/file/file.post_update.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 18 | ERROR | [x] Expected 1 newline at end of file; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 425ms; Memory: 8MB


FILE: /Users/alex/dev/drupal/core/modules/file/src/Plugin/Field/FieldType/FileItem.php
--------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------
 196 | ERROR | [x] Whitespace found at end of line
--------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------

Time: 3.76 secs; Memory: 10MB

-e PHPCS: core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php passed

FILE: /Users/alex/dev/drupal/core/modules/file/tests/src/Functional/FileFieldDisplayTest.php
--------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------
 187 | ERROR | [x] Whitespace found at end of line
--------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------

Time: 2.66 secs; Memory: 10MB


FILE: /Users/alex/dev/drupal/core/modules/file/tests/src/Functional/Update/FileDescriptionRequiredUpdateTest.php
----------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------------
 44 | ERROR | [x] Expected 1 newline at end of file; 0 found
----------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------
claudiu.cristea’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs change record
FileSize
4.02 KB
14.63 KB

Added change record. Fixed minor code standards issues.

alexpott’s picture

Title: Make or allow making description a required field » Add a setting to make description a required field for file items
claudiu.cristea’s picture

Reverting a too far change.

alexpott’s picture

Issue summary: View changes

Added the issue summary template. It could do with being properly completed.

claudiu.cristea’s picture

Issue summary: View changes

Updated the IS according to template.

xjm’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs usability review

Thanks for your work on this issue! I've a couple questions about it:

  1. Does this option need to be added in core? It is a fairly trivial form alter for contrib or custom code to support this option.
  2. Even if the configuration setting is provided in core, do we need to expose it in the core UI? More form fields, descriptions, text, etc. is all detrimental to usability, so we need to weigh the usability improvement of site owners easily requiring readable filenames against the usability cost of adding the form field.

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:

+++ b/core/modules/file/src/Plugin/Field/FieldType/FileItem.php
@@ -188,11 +189,24 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
+      '#description' => $this->t('Whether or not the description field is required.'),

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 #ux channel in Drupal Slack, and in particular from the weekly UX meeting Fridays at 1500 UTC.

xjm’s picture

Unrelatedly, this is sort of false:

Data model changes
None.

Additions to the config schemata are data model additions and should probably be documented there in the IS.

alexpott’s picture

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

alexpott’s picture

  1. +++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php
    @@ -267,6 +269,10 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    +    if (!empty($element['#description_field_required'])) {
    +      $element['#element_validate'][] = [static::class, 'validateRequiredDescription'];
    +    }
    
    @@ -332,6 +338,32 @@ public static function value($element, $input, FormStateInterface $form_state) {
    +  /**
    +   * #element_validate callback to check if a required description is filled in.
    +   *
    +   * @param array $element
    +   *   An associative array containing the properties and children of the
    +   *   generic form element.
    +   * @param \Drupal\Core\Form\FormStateInterface $form_state
    +   *   The current state of the form.
    +   * @param array $complete_form
    +   *   The complete form structure.
    +   */
    +  public static function validateRequiredDescription(array &$element, FormStateInterface $form_state, array &$complete_form) {
    +    // Skip validation if a file is being uploaded or deleted.
    +    $parent = array_slice($element['#parents'], 0, -1);
    +    $trigger_parents = $form_state->getTriggeringElement()['#parents'];
    +    if (!array_diff($parent, array_intersect($parent, $trigger_parents))) {
    +      if (in_array(array_pop($trigger_parents), ['upload_button', 'remove_button'], TRUE)) {
    +        return;
    +      }
    +    }
    +    // Throw a validation error when the file is present but has no description.
    +    if (!empty($element['fids']['#value']) && empty($element['description']['#value'])) {
    +      $form_state->setError($element, t('@name field is required.', ['@name' => $element['description']['#title']]));
    +    }
    +  }
    

    If #56 is done then this code should be obsolete.

  2. +++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php
    @@ -210,9 +210,10 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    -      'display_default' => NULL,
    -      'display_field' => NULL,
    -      'description_field' => NULL,
    +      'display_default' => FALSE,
    +      'display_field' => FALSE,
    +      'description_field' => FALSE,
    

    This changes of value are a bit odd - why is this being done here apart from for "consistency"?

MrPaulDriver’s picture

Has anyone had chance to do further work on this?

claudiu.cristea’s picture

Issue summary: View changes
FileSize
182.69 KB
84.25 KB

@xjm

  • #54.1, 2: This is more or less symmetrical to title_field_required from image item. And if that exists in core and is exposed in UI, I see no reason why this one shouldn't be.
  • #54: True. Removed the useless description.
  • #55: Fixed IS.

@alexpott

  • #56, #57.1: Yeah, very elegant. Done. I've also added a JSON:API test.
  • #57.2: Yes, it's consistency and also the settings semantics whispers me that those are booleans. I agree that are out of scope, it was just an easy win with no BC implications.

Ready for another review.

claudiu.cristea’s picture

To whom it may concern: here's an 8.9.x unofficial version. This patch is not for review.

pfrenssen’s picture

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

benjifisher’s picture

Issue tags: -Needs usability review

Usability review

We discussed this issue at #3200598: Drupal Usability Meeting 2021-02-26.

From #54:

  1. Does this option need to be added in core? It is a fairly trivial form alter for contrib or custom code to support this option.
  2. Even if the configuration setting is provided in core, do we need to expose it in the core UI? More form fields, descriptions, text, etc. is all detrimental to usability, so we need to weigh the usability improvement of site owners easily requiring readable filenames against the usability cost of adding the form field.

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.

MrPaulDriver’s picture

Good to see this was endorsed by the UX group.

Is there anything to prevent this finding it's way in the core?

claudiu.cristea’s picture

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

MrPaulDriver’s picture

Sorry. Not up to speed with the new MR workflow.

Madhu kumar’s picture

FileSize
118.88 KB

Can't apply patch #44 on 9.2.x , added screenshot for the reference.

claudiu.cristea’s picture

@MrPaulDriver, that's very simple:

claudiu.cristea’s picture

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

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

scoisne’s picture

Hello, 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.

        "patches": {
            "drupal/core": {
                "2320877 - Description required": "https://git.drupalcode.org/project/drupal/-/merge_requests/282.diff",
            },

I'm trying on a fresh D9 install (with only cweagans/composer-patches for applying patches)

I'm missing something ?

GuillaumeG’s picture

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

anweshasinha’s picture

I am working in this

anweshasinha’s picture

Hi,
I have worked on this. Please review my work.

anweshasinha’s picture

FileSize
5.52 KB
anweshasinha’s picture

Made certain changes in the patch. The updated one is given below.

ranjith_kumar_k_u’s picture

Fixed custom command failure

AaronMcHale’s picture

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

paulocs’s picture

The MR should be actually merged into 9.3.x branch.

paulocs’s picture

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

marcusvsouza’s picture

FileSize
30.68 KB

The MR in comment #80 works as expected, implemented in all types of media content with no code standards problems.
Image attached for reference.

marcusvsouza’s picture

Status: Needs review » Reviewed & tested by the community

Changing to RTBC!

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

xjm’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs manual testing

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

  1. There is #states use present that presumably supports the progressive disclosure, but not JavaScript test coverage for the behavior. We should add that.
  2. It'd be good to also have clear confirmation from manual testing that the progressive disclosure works as expected when checking and un-checking the box.
  3. The MR diff does not apply to 10.0.x. (It does apply to 9.4.x, so a new MR could be created for 9.4.x easily from the current diff. We need both here; 9.3.x is bugfix-only now.)
  4. We also need the upgrade path tests updated to use the 9.3 fixtures (rather than the 8.8 ones).
  5. Edit: REST/JSON:API test coverage would also be good given #56.

Thanks everyone!

xjm’s picture

Also adding credit for helpful reviews. Thanks, reviewers!

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

megadesk3000’s picture

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

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

szato’s picture

Using MR#3117 with 9.5.7, works. Thank you.

florianmuellerCH’s picture

FileSize
5.53 KB

As this affects core and I have the need to apply multiple patches, I created a patch for 10.x to apply.

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

capysara’s picture

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

capysara’s picture

Issue summary: View changes

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

capysara’s picture

Manual testing (WIP)

I used the Live preview via Tugboat (TIL there's a Live preview via Tugboat!)

  1. Create a file field (field_myfile1) in the Basic page content type admin/structure/types/manage/page/fields/add-field
  2. Check "Enable Description field"
  3. "Require the Description field" displays and is not enabled
  4. Uncheck "Enable..."
  5. "Require..." field is not displayed & Save
  6. Create a file field (field_myfile2)
  7. Enable Description but don't Require & Save
  8. Create a file field (field_myfile3)
  9. Enable Description and Require & Save
  10. Add Basic page node & Add files to fields
  11. Save without adding a description to the required field_myfile3
  12. Unable to save (fails both client- and server-side validation). Expected.
  13. Add a description to myfile3 and save
  14. 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.
  1. Create new media type Newmedia3, Media source: File
  2. Edit the File settings - Enable/Require description
  3. Add media item of type Newmedia3 /media/add/newmedia3
  4. Description is required
  5. Edit basic page content type and add Media field (field_newmedia3), Media type: Newmedia3
  6. There's nowhere to add a description. But that's how it's always been, right?
  7. Add node of type Basic page, Add media to newmedia3 field. Choose file, there's only a Name field, no description field.
  8. Should there be a description field on file upload (for Media fields when uploading through the media library) since the description is required? Is that out of scope for this ticket? Note: When you edit the media item itself, the Description field displays and is required.

Only local images are allowed.

capysara’s picture

Issue summary: View changes

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, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

malcomio’s picture

With 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::formElement

Vanitha Sophia’s picture

To address the Undefined array key "description_field" in \Drupal\file\Plugin\Field\FieldWidget\FileWidget::formElement for issue 104, we can use this patch

guardiola86’s picture

Status: Needs work » Needs review

Tested and it's working fine

poker10’s picture

Status: Needs review » Needs work

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

claudiu.cristea’s picture

Status: Needs work » Needs review
poker10’s picture

Status: Needs review » Needs work

There is a failure in the MR pipeline, which does not looks like a random one, but related to the MR changes:

There was 1 error:
    
    1) Drupal\Tests\file\Functional\FileFieldDisplayTest::testDescToggle
    Behat\Mink\Exception\ElementNotFoundException: Button with
    id|name|label|value "Save and continue" not found.
    
    /builds/issue/drupal-2320877/core/tests/Drupal/Tests/WebAssert.php:144
    /builds/issue/drupal-2320877/core/tests/Drupal/Tests/UiHelperTrait.php:78
    /builds/issue/drupal-2320877/core/modules/file/tests/src/Functional/FileFieldDisplayTest.php:178
    /builds/issue/drupal-2320877/vendor/phpunit/phpunit/src/Framework/TestResult.php:728

https://git.drupalcode.org/issue/drupal-2320877/-/jobs/507087

claudiu.cristea changed the visibility of the branch 2320877-description-required-10.0.x to hidden.

claudiu.cristea changed the visibility of the branch 2320877-9.5 to hidden.

claudiu.cristea changed the visibility of the branch 2320877-10.1.x to hidden.