Support new upload validator syntax from D10.2+

Created on 11 April 2024, 7 months ago
Updated 20 June 2024, 5 months ago

Problem/Motivation

After installing the module and adding an SVG field, the field widget shows a duplicate line of allowed file type help text.

Proposed resolution

Replace SVG field upload validator syntax with the new one introduced in Drupal 10.2. See Change Record: file_validate and related functions are deprecated and replaced with file.validator service and Constraint plugins β†’

We must support both the old and new syntax based on which version of Drupal is being used. We can leverage DeprecationHelper, introduced in Drupal 10.1 as the means for writing the fallback logic for the legacy format. In pseudo-code, this translates roughly to:

// If DeprecationHelper not installed, use old syntax:
$element['#upload_validators']['file_validate_extensions'][0] = 'svg';
// Else If Drupal Core >= 10.2
$element['#upload_validators']['FileExtension'] => ['extensions' => 'svg'];
// Else
$element['#upload_validators']['file_validate_extensions'][0] = 'svg';
πŸ› Bug report
Status

Fixed

Version

2.3

Component

User interface

Created by

πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024