Add a setting to make description a required field for file items

Created on 13 August 2014, over 10 years ago
Updated 30 March 2023, about 2 years ago

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

N/A

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

Feature request
Status

Needs work

Version

10.1

Component
File module 

Last updated 11 days ago

Created by

🇺🇸United States charles belov San Francisco, CA, US

Live updates comments and jobs are added and updated live.
  • Needs manual testing

    The change/bugfix cannot be fully demonstrated by automated testing, and thus requires manual testing in a variety of environments.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇭🇺Hungary szato

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

  • 🇨🇭Switzerland florianmuellerch Aarau, Switzerland

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

  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 2 years ago
    29,374 pass, 2 fail
  • @capysara opened merge request.
  • 🇺🇸United States capysara

    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 Add a setting to make description a required field for file items Needs work still need to be implemented. I'm working on manually testing it.

  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 2 years ago
    29,374 pass, 2 fail
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 2 years ago
    29,375 pass
  • 🇺🇸United States capysara

    Manual testing (WIP)

    I used the Live preview via Tugboat (TIL I learned 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)
    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.
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 2 years ago
    29,375 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update almost 2 years ago
    28,526 pass, 2 fail
  • @claudiucristea opened merge request.
  • 🇬🇧United Kingdom malcomio

    With the patch from #94 applied, we have observed PHP warnings, similar to 🐛 Undefined array key "description_field_required" in \Drupal\file\Plugin\Field\FieldWidget\FileWidget::formElement Needs work :

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

  • 🇮🇳India Vanitha Sophia

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

  • Status changed to Needs review over 1 year ago
  • last update over 1 year ago
    Patch Failed to Apply
  • 🇪🇸Spain guardiola86

    Tested and it's working fine

  • Status changed to Needs work over 1 year ago
  • 🇸🇰Slovakia poker10

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

  • Merge request !5876Drupal 11.x version → (Open) created by claudiu.cristea
  • Pipeline finished with Failed
    over 1 year ago
    Total: 636s
    #65829
  • Status changed to Needs review over 1 year ago
  • Status changed to Needs work over 1 year ago
  • 🇸🇰Slovakia poker10

    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

  • 🇷🇴Romania claudiu.cristea Arad 🇷🇴

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

  • 🇷🇴Romania claudiu.cristea Arad 🇷🇴

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

  • 🇷🇴Romania claudiu.cristea Arad 🇷🇴

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

  • Pipeline finished with Failed
    10 months ago
    Total: 198s
    #213245
  • Pipeline finished with Failed
    10 months ago
    #213249
  • Pipeline finished with Failed
    10 months ago
    Total: 618s
    #213279
  • Pipeline finished with Success
    10 months ago
    Total: 588s
    #213303
  • Status changed to Needs review 10 months ago
  • 🇷🇴Romania claudiu.cristea Arad 🇷🇴

    Tests are green. Ready for a final review.

  • Pipeline finished with Canceled
    10 months ago
    Total: 83s
    #214040
  • 🇷🇴Romania claudiu.cristea Arad 🇷🇴

    Drupal 10.3.x version patch

  • Pipeline finished with Success
    10 months ago
    Total: 1409s
    #214041
  • 🇧🇷Brazil carolpettirossi Campinas - SP

    I tested the patch provided on #115 on Drupal 10.3.0, and it worked as expected. See below the test steps I executed:

  • Status changed to Needs work 10 months ago
  • The 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.

  • Pipeline finished with Success
    10 months ago
    Total: 588s
    #219741
  • 🇷🇴Romania claudiu.cristea Arad 🇷🇴

    Manual testing has been performed in #100 Add a setting to make description a required field for file items Needs work

  • Pipeline finished with Success
    10 months ago
    Total: 538s
    #219825
  • Pipeline finished with Success
    10 months ago
    Total: 540s
    #219843
  • 🇷🇴Romania claudiu.cristea Arad 🇷🇴

    Trying to revive this

  • 🇷🇴Romania claudiu.cristea Arad 🇷🇴

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

  • 🇷🇴Romania claudiu.cristea Arad 🇷🇴

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

  • 🇷🇴Romania claudiu.cristea Arad 🇷🇴

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

  • 🇷🇴Romania claudiu.cristea Arad 🇷🇴

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

  • Pipeline finished with Failed
    16 days ago
    Total: 159s
    #479918
  • Pipeline finished with Failed
    16 days ago
    Total: 545s
    #479921
  • Merge request !11921D 10.4 → (Closed) created by claudiu.cristea
  • Pipeline finished with Success
    16 days ago
    Total: 599s
    #479981
  • Pipeline finished with Failed
    16 days ago
    #479985
  • 🇷🇴Romania claudiu.cristea Arad 🇷🇴

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

  • 🇷🇴Romania claudiu.cristea Arad 🇷🇴

    MR !5876 is for 11.x and review.

  • Pipeline finished with Failed
    16 days ago
    #480059
  • 🇺🇸United States charles belov San Francisco, CA, US

    Alas, 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

  • 🇷🇴Romania claudiu.cristea Arad 🇷🇴

    You should use MR 5876 for 11.x

  • 🇺🇸United States charles belov San Francisco, CA, US

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

  • 🇩🇰Denmark ressa Copenhagen

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

  • 🇺🇸United States charles belov San Francisco, CA, US

    Interesting. 11.x-dev still fails for me but 11.1.x-dev works. Tested with 11.1.x-dev on simplytest.me.

    Tested:

    • description required and initially not entered, then enter when prompted
    • description required and entered first time
    • description optional and not entered
    • description optional and entered

    All work for me.

Production build 0.71.5 2024