Problem/Motivation

When using the Webform QR Code Element module and configuring the QR Code element to attach a PDF template, uploading a PDF template results in a fatal error.

The error occurs when uploading the PDF template through the PDF file template field in the QR Code element configuration.

The following exception is thrown:

Drupal\Component\Plugin\Exception\PluginNotFoundException:
The "file_validate_extensions " plugin does not exist.

The error indicates that the module is still using the legacy file_validate_extensions validator, which is no longer available as a validation constraint plugin in the current Drupal validation API.

Steps to reproduce

  1. Install and enable the Webform QR Code Element module.
  2. Create or edit a Webform.
  3. Add a QR Code element.
  4. Enable PDF document under Email attachments.
  5. In the PDF file template field, upload a PDF file.
  6. Submit/save the Webform element configuration.

An unexpected error is displayed and the PDF template cannot be uploaded.

Actual result

The upload fails with the following error:

Drupal\Component\Plugin\Exception\PluginNotFoundException:
The "file_validate_extensions " plugin does not exist.

The stack trace points to Drupal's file validation process:

Drupal\Core\Validation\ConstraintFactory->createInstance()
Drupal\Component\Plugin\PluginManagerBase->createInstance()
Drupal\Core\Validation\ConstraintManager->create()
Drupal\file\Validation\FileValidator->validate()
Drupal\file\Upload\FileUploadHandler->handleFileUpload()
file_save_upload()
file_managed_file_save_upload()
Drupal\file\Element\ManagedFile::valueCallback()

The list of available validation constraints includes:

FileExtension
FileExtensionSecure
FileSizeLimit
FileNameLength
FileIsImage
FileImageDimensions

but does not include the legacy file_validate_extensions plugin.

Proposed resolution

Replace the deprecated file_validate_extensions upload validator with the FileExtension validation constraint.

Patch

diff --git a/src/Plugin/WebformElement/QrCode.php b/src/Plugin/WebformElement/QrCode.php index OLD_HASH..NEW_HASH 100644 --- a/src/Plugin/WebformElement/QrCode.php +++ b/src/Plugin/WebformElement/QrCode.php @@ -130,7 +130,9 @@ class QrCode extends WebformComputedToken { 'pdf_template' => [ '#type' => 'managed_file', '#upload_location' => 'public://', '#upload_validators' => [ - 'file_validate_extensions' => ['pdf'], + 'FileExtension' => [ + 'extensions' => 'pdf', + ], ], '#title' => t('PDF file template') . ' (' . t('optional') . ')', ],

This changes the validator from:

'file_validate_extensions' => ['pdf'],

to the current validation constraint:

'FileExtension' => [
  'extensions' => 'pdf',
],

Expected result

The PDF template should be successfully uploaded when configuring the QR Code element, with the file restricted to the PDF extension, without triggering a PluginNotFoundException.

Additional information

The issue appears to be related to compatibility with the current Drupal file validation API, where file_validate_extensions is no longer recognized as a validation constraint plugin.

The proposed patch only changes the file extension validation used by the PDF template upload field.

Comments

moudeen created an issue. See original summary.

moudeen’s picture

Issue summary: View changes
gogowitsch’s picture

Thanks for opening an issue! I’ll let you know once I have news - probably within the next 7 days.

moudeen’s picture

Issue summary: View changes
gogowitsch’s picture

Issue summary: View changes

The file_validate_extensions function was dropped with Drupal 11 - see change record 3363700.

I applied the suggested fix and will release a new version 1.4.0.

Thanks, @moudeen!

  • gogowitsch committed ae44860b on 1.x
    fix: #3612685 Drupal 10/11 compatibility issue when uploading PDF...
gogowitsch’s picture

Issue summary: View changes
Status: Active » Fixed

The bugfix is now released.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

gogowitsch’s picture

Title: Drupal 10/11 compatibility issue when uploading PDF template » Drupal 11 compatibility issue when uploading PDF template
Issue summary: View changes

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.