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
- Install and enable the Webform QR Code Element module.
- Create or edit a Webform.
- Add a QR Code element.
- Enable PDF document under Email attachments.
- In the PDF file template field, upload a PDF file.
- 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
Comment #2
moudeen commentedComment #3
gogowitsch commentedThanks for opening an issue! I’ll let you know once I have news - probably within the next 7 days.
Comment #4
moudeen commentedComment #5
gogowitsch commentedThe
file_validate_extensionsfunction 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!
Comment #7
gogowitsch commentedThe bugfix is now released.
Comment #9
gogowitsch commented