Unable to access unchanged values in FileWidget::formElement()

Created on 25 November 2017, over 7 years ago
Updated 28 May 2025, 2 days ago

When uploading new files to a file field (which allows multiple values) there is no way to access original values in FileWidget::formElement() at form rebuilding process since they are overwritten by the new ones. The problem arises when some other widget which extends file widget needs to access these original values.

In case of VisualN , file field and widget are used as a base for the VisualN file field and widget respectively. For each VisualN file delta user can choose a visualization style to be applied to the data in the uploaded file to create a visualization. Each style has its configuration which can be overridden by the one stored for the delta. If user changes the configuration and saves the entity, later the style and configuration can be changed editing the entity.

Steps to demonstrate a case when initial unchanged values are required:

  1. Create a content type with a VisualN file (and configure the formatter)
  2. Create a new node and upload a file
  3. Choose a style and change default configuration
  4. Save the node
  5. Open the node for edit
  6. Change the style to some other one
  7. Upload a new file
  8. Change the style (for the fist file) back to the initial one

So at the last step initial unchanged configuration (for the first delta) is needed though it was overridden by the new value, thus the user needs to refresh the form and reupload required files (and any other changes) if he wants the configuration for the first delta to get back to its initial values.

Feature request
Status

Closed: cannot reproduce

Version

11.0 🔥

Component

file.module

Created by

🇷🇺Russia kpv

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

Comments & Activities

Not all content is available!

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

  • 🇮🇳India mohit_aghera Rajkot

    I am not able to reproduce the issue in vanilla Drupal core.

    I did following steps to reproduce:
    - Use article content type
    - Add file field with "Description" field enabled in file widget
    - Set cardinality to unlimited.
    - Create new article and add one file with description.
    - Save article.
    - Edit article again and add new file.
    - Ensure that first file's description remains unchanged

    Besides above steps, I was able to see all the values in $items of Drupal\file\Plugin\Field\FieldWidget\FileWidget's formElement method.

    Feel free to reopen if you notice additional issues with the updated steps to reproduce.

Production build 0.71.5 2024