Hide Uppy widget if file upload element is not available

Created on 29 April 2022, about 2 years ago
Updated 12 June 2024, 14 days ago

Problem/Motivation

If the file is already uploaded, the default upload input element is hidden. This is default Drupal core and can be observed in
\Drupal\file\Element\ManagedFile::preRenderManagedFile():

// If we already have a file, we don't want to show the upload controls.
if (!empty($element['#value']['fids'])) {
  if (!$element['#multiple']) {
    $element['upload']['#access'] = FALSE;
    $element['upload_button']['#access'] = FALSE;
  }
}

However, Uppy widget is still visible even though the input[type="file"] is not available on the page.

Steps to reproduce

1. Create an entity with File field and Uppy widget enabled (set files cardinality to 1);
2. Open "Edit" page;
3. You'll see an uploaded file and widget to upload more, which is confusing;

Proposed resolution

Hide the widget if file input element is not found.

Before:

After:

Remaining tasks

Review, commit.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine Matroskeen πŸ‡ΊπŸ‡¦ Ukraine, Lutsk

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.

Production build 0.69.0 2024