PHP warnings from FileUrlWidget

Created on 28 May 2024, 11 months ago
Updated 30 May 2024, 11 months ago

Problem/Motivation

In some scenarios, the widget throws PHP warnings/errors.

Steps to reproduce

- Click "Remote file URL" radio and fill in an invalid URL (e.g: foo)
- Now click the "Upload file" radio twice and upload a file
- > ERROR: "TypeError: Drupal\file_url\FileUrlHandler::fileToUrl(): Argument #1 ($file) must be of type Drupal\file\FileInterface, null given, called in /var/www/html/web/modules/contrib/file_url/src/Plugin/Field/FieldWidget/FileUrlWidget.php on line 277 in Drupal\file_url\FileUrlHandler::fileToUrl() (line 26 of /var/www/html/web/modules/contrib/file_url/src/FileUrlHandler.php)"

There are other cases I believe.

Proposed resolution

The whole module architecture is rather convoluted and sub-optimal, see also #3327568: [3.x proposal] Re-architect the module β†’ .
It would be great to rework the backend/storage and UI, but until this lands the main issue seems to be from the value callback in the widget. Mainly, fids should not be populated/returned if the URL is invalid.

πŸ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium herved

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

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024