Following the update to Drupal 10.2, file uploads are resulting in an AJAX error. The error log:

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "webform_file_validate_extensions" plugin does not exist. Valid plugin IDs for Drupal\Core\Validation\ConstraintManager are: Callback, Blank, NotBlank, Email, Choice, BlockContentEntityChanged, CKEditor5EnabledConfigurablePlugins, SourceEditingPreventSelfXssConstraint, CKEditor5FundamentalCompatibility, UniqueLabelInList, SourceEditingRedundantTags, CKEditor5ToolbarItem, CKEditor5ToolbarItemConditionsMet, CKEditor5ToolbarItemDependencyConstraint, StyleSensibleElement, CKEditor5MediaAndFilterSettingsInSync, CKEditor5Element, CommentName, ModerationState, DateTimeFormat, FileValidation, FileUriUnique, FileImageDimensions, FileNameLength, FileSizeLimit, FileIsImage, FileExtensionSecure, FileExtension, LinkExternalProtocols, LinkAccess, LinkType, LinkNotExistingInternal, oembed_resource, MenuTreeHierarchy, MenuSettings, PathAlias, RedirectSourceLinkType, TaxonomyHierarchy, UserMailRequired, ProtectedUserField, UserMailUnique, UserName, UserNameUnique, ExtensionName, ExtensionExists, ValidPath, UniquePathAlias, PluginExists, EntityUntranslatableFields, ReferenceAccess, EntityType, ImmutableProperties, Bundle, EntityChanged, ValidReference, EntityHasField, RequiredConfigDependencies, ConfigExists, AllowedValues, NotNull, ComplexData, Range, UniqueField, Count, Regex, ValidKeys, Length, Null, PrimitiveType, Uuid in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 53 of /[...]/html/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).

I'm not sure, but could this have something to do with the new filename sanitation?

EDIT:
Here's a stack trace:

#0 [...]/html/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryCachedTrait.php(25): Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition()
#1 [...]/html/core/lib/Drupal/Core/Validation/ConstraintFactory.php(21): Drupal\Core\Plugin\DefaultPluginManager->getDefinition()
#2 [...]/html/core/lib/Drupal/Component/Plugin/PluginManagerBase.php(83): Drupal\Core\Validation\ConstraintFactory->createInstance()
#3 [...]/html/core/lib/Drupal/Core/Validation/ConstraintManager.php(84): Drupal\Component\Plugin\PluginManagerBase->createInstance()
#4 [...]/html/core/modules/file/src/Validation/FileValidator.php(56): Drupal\Core\Validation\ConstraintManager->create()
#5 [...]/html/core/modules/file/src/Upload/FileUploadHandler.php(243): Drupal\file\Validation\FileValidator->validate()
#6 [...]/html/core/modules/file/file.module(658): Drupal\file\Upload\FileUploadHandler->handleFileUpload()
#7 [...]/html/core/modules/file/file.module(536): file_save_upload()
#8 [...]/html/core/modules/file/file.module(1007): _file_save_upload_from_form()
#9 [...]/html/core/modules/file/src/Element/ManagedFile.php(76): file_managed_file_save_upload()
#10 [internal function]: Drupal\file\Element\ManagedFile::valueCallback()
#11 [...]/html/core/lib/Drupal/Core/Form/FormBuilder.php(1266): call_user_func_array()
#12 [...]/html/core/lib/Drupal/Core/Form/FormBuilder.php(1006): Drupal\Core\Form\FormBuilder->handleInputElement()
#13 [...]/html/core/lib/Drupal/Core/Form/FormBuilder.php(1076): Drupal\Core\Form\FormBuilder->doBuildForm()
#14 [...]/html/core/lib/Drupal/Core/Form/FormBuilder.php(1076): Drupal\Core\Form\FormBuilder->doBuildForm()
#15 [...]/html/core/lib/Drupal/Core/Form/FormBuilder.php(1076): Drupal\Core\Form\FormBuilder->doBuildForm()
#16 [...]/html/core/lib/Drupal/Core/Form/FormBuilder.php(1076): Drupal\Core\Form\FormBuilder->doBuildForm()
#17 [...]/html/core/lib/Drupal/Core/Form/FormBuilder.php(579): Drupal\Core\Form\FormBuilder->doBuildForm()
#18 [...]/html/core/lib/Drupal/Core/Form/FormBuilder.php(325): Drupal\Core\Form\FormBuilder->processForm()
#19 [...]/html/core/lib/Drupal/Core/Entity/EntityFormBuilder.php(48): Drupal\Core\Form\FormBuilder->buildForm()
#20 [...]/html/modules/contrib/webform/src/Entity/Webform.php(1257): Drupal\Core\Entity\EntityFormBuilder->getForm()
#21 [...]/html/modules/contrib/webform/src/Controller/WebformEntityController.php(77): Drupal\webform\Entity\Webform->getSubmissionForm()
#22 [internal function]: Drupal\webform\Controller\WebformEntityController->addForm()
#23 [...]/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#24 [...]/html/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#25 [...]/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext()
#26 [...]/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#27 [...]/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#28 [...]/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#29 [...]/html/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
#30 [...]/html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#31 [...]/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#32 [...]/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#33 [...]/html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
#34 [...]/html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#35 [...]/html/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#36 [...]/html/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
#37 [...]/html/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#38 [...]/html/index.php(19): Drupal\Core\DrupalKernel->handle()
#39 {main}

Issue fork webform-3409599

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

greatmatter created an issue. See original summary.

greatmatter’s picture

Issue summary: View changes
cilefen’s picture

greatmatter’s picture

While this is probably not the long-term fix, I commented out line 251 of [ROOT]/modules/contrib/webform/src/Plugin/WebformElement/WebformManagedFileBase.php:251

And this error goes away... But I'm worried that I'm opening a can of worms.

greatmatter’s picture

@cilefen thank you. I don't have anything like that in the config folder, but I do see the following in my site filebase:

[ROOT]/modules/contrib/webform/src/Plugin/WebformElement/WebformManagedFileBase.php:245:    // Define 'webform_file_validate_extensions' which allows file
[ROOT]/modules/contrib/webform/src/Plugin/WebformElement/WebformManagedFileBase.php:247:    // 'webform_file_validate_extensions' will be ignored by file_validate().
[ROOT]/modules/contrib/webform/src/Plugin/WebformElement/WebformManagedFileBase.php:251:    $element['#upload_validators']['webform_file_validate_extensions'] = [];
[ROOT]/modules/contrib/webform/includes/webform.theme.inc:665:  if (isset($upload_validators['webform_file_validate_extensions'])) {
ryo ichiyama’s picture

StatusFileSize
new4.22 KB

I have also seen the same logs as @greatmatters when uploading files since updating Drupal Core to 10.2.
Additionally, the browser displays the attached error message.
The version of the Webform module (6.2.2) has not changed before or after the Core update.

Any hints would be appreciated.

cilefen’s picture

Are any patches installed on these sites?

cilefen’s picture

Also, please post the YAML of a simple form that exhibits the bug.

cilefen’s picture

I can’t reproduce this by intuiting the steps.

ryo ichiyama’s picture

Hello.

I got an error in my local development environment, so I tried it in the staging environment and got the same error.

Below is the minimal YAML source.

file1:.
'#type': managed_file
'#title': File1
'#file_preview': file
'#file_extensions': 'pdf jpg jpeg png'
'#sanitize': true
'#button': true
'#button__title': Upload1

Also, nothing has been patched for the Webform module.

jonathanhulet’s picture

Hello

I've the same problem after module updated in 6.2 and also Drupal 10.2.0

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "webform_file_validate_extensions" plugin does not exist. Valid plugin IDs for Drupal\Core\Validation\ConstraintManager are: Callback, Blank, NotBlank, Email, Choice, BlockContentEntityChanged, CropTypeAspectRatioValidation, CropTypeMachineNameValidation, DateTimeFormat, QueueSize, FileIsImage, FileSizeLimit, FileExtensionSecure, FileImageDimensions, FileValidation, FileNameLength, FileUriUnique, FileExtension, jsonapi_extras__duplicate_field, LinkType, LinkNotExistingInternal, LinkExternalProtocols, LinkAccess, oembed_resource, MenuSettings, ParagraphsLibraryItemHasAllowedParagraphsType, PathAlias, RedirectSourceLinkType, SchedulerUnpublishOn, SchedulerPublishOn, TaxonomyHierarchy, UserName, UserMailRequired, ProtectedUserField, UserNameUnique, UserMailUnique, VideoEmbedValidation, MenuTreeHierarchy, ExtensionName, ExtensionExists, RequiredConfigDependencies, ConfigExists, Count, ValidKeys, Length, Null, Range, UniqueField, ComplexData, Regex, PrimitiveType, Uuid, AllowedValues, NotNull, UniquePathAlias, ValidPath, EntityUntranslatableFields, EntityChanged, ImmutableProperties, EntityHasField, Bundle, ValidReference, ReferenceAccess, EntityType, PluginExists in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 53 of /var/www/html/web/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).

I follow this issue

benaboki’s picture

I am also having the same issue with Drupal 10.2, Webform 6.2.2 and PHP 8.2. Users cannot upload files

Uncaught PHP Exception Drupal\Component\Plugin\Exception\PluginNotFoundException: "The "webform_file_validate_extensions" plugin does not exist. Valid plugin IDs for Drupal\Core\Validation\ConstraintManager are: ...

benaboki’s picture

#4 allows submissions to go through so I have it as a temporary fix as well. Thanks @greatmatter

cilefen’s picture

Is this problem analogous to #3409317: Core version 10.2 imce error?

greatmatter’s picture

@cilefen Possibly, though I don't have IMCE on any of my sites.

This might play a bigger role:
https://www.drupal.org/node/3363700 - file_validate and related functions are deprecated and replaced with file.validator service and Constraint plugins

cilefen’s picture

I said "analogous", not "caused by".

Anyway, we just got hit with this one so I have a form that reproduce this now.

ankithashetty’s picture

+1 to this issue.
For now tried the #4 suggestion as a workaround.

cilefen’s picture

I think the fact that no function exists of the name webform_file_validate_extensions is the problem here.

sakthi_dev’s picture

I think the implementation is wrong here. Why we need a condition to check in preprocess_file_upload_help. The preprocess itself will get invoke on file help. Even if we want a condition there, I think it should be a variable and not as a callback function in a array and also is not a validation just altering the rendered value to have comma instead of space. So the solution would be removing the callback function addition from WebformManagedFileBase.php and also removing the if condition from webform_preprocess_file_upload_help in webform.theme.inc.

Correct me if I'm wrong.

cilefen’s picture

Priority: Major » Critical

I would go so far as to make this a critical for this module, because file uploads are a major feature.

damienmckenna’s picture

I have a brand new 10.2.x install with Webform 6.2.x, I added a basic managed file element to the out-of-the-box contact form and could not reproduce this problem. Can someone please work out the exact steps to reproduce the problem? Thank you.

cilefen’s picture

What about the element in #10?

damienmckenna’s picture

damienmckenna’s picture

FYI the core change introduced a subtle bug whereby if a validator passed through #upload_validators did not exist as a function it was assumed to be a constraint plugin, whereas some contrib modules used it as a namespaced variable that would ultimately be passed through to hook_file_validate().

damienmckenna’s picture

sakthi_dev’s picture

Status: Active » Needs review

Updated the code as per comment #19. Please review.

jrb’s picture

The changes in MR 388 fixed the issue for us. Attached is a patch with the diffs as of today.

raffie’s picture

I have never installed a patch before

where do I place that patch

composer.json

"extra": {
"patches": {
"drupal/??": {
"??": "https://www.drupal.org/files/issues/2023-12-22/3409599-28.mr388.webform_..."

}
}
}

damienmckenna’s picture

@raffie: Please see the official docs on how to use a patch file; you'll want to add it to the website project's root composer.json file: https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupa...

jwnukoski’s picture

Patch seems to have worked on:
Drupal 10.2.0
PHP 8.1.26
MariaDB 10.4.25
drupal/webform 6.2.2

composer.json example:

"extra": {
	...,

	"patches": {
		"drupal/webform": {
                	"Issue 3409599. Fix file upload.": "https://git.drupalcode.org/project/webform/-/merge_requests/388.patch"
            	}
	}
}
ethangeorgi’s picture

Patch worked for us, too. Thank you!

Drupal 10.2.0
PHP 8.1.26
MariaDB 10.4.25
drupal/webform 6.2.2

leducdubleuet’s picture

Status: Needs review » Reviewed & tested by the community

Patch worked for us as well, thank you very much!

jrockowitz’s picture

Status: Reviewed & tested by the community » Needs work

I understand people are trying to fix this issue, but the ticket summary should document the problem and resolution.

Right now, the MR seems to be removing file extension validation for all versions of Drupal, even though the problem is only occurring in 10.2.x

cilefen’s picture

The core issue is fixed. Is this even still happening on 10.2.x?

leducdubleuet’s picture

As of this morning, the patch is still needed with 10.2 for the file upload to work properly so yes this is still happening.

leducdubleuet’s picture

I also tested the file extension validation and it is still working even with the patch so the fix does not completely remove the file extension validation.

It removes the line :

$element['#upload_validators']['webform_file_validate_extensions'] = [];

But we still have :

$element['#upload_validators']['file_validate_extensions'] = [$this->getFileExtensions($element)];
sakthi_dev’s picture

Just for clarification. The issue is because of "webform_file_validate_extensions" callback function and it doesn't exists but that is used as a if condition in the hook. Also, it is not validating the file extension but just adding the comma to the allowed list of extension in the frontend. I think this issue is not related to removing the upcoming deprecated function and also mentioned issue is not related to it.

Please correct me if I'm wrong.

cilefen’s picture

Just to be clear, I am referring to testing with 10.2.x, the branch head, not with 10.2.0 release.

damienmckenna’s picture

With the core change does this mean that the validation logic in Webform should be rewritten to be a constraint instead of just a function?

cilefen’s picture

Is this fixed by 10.2.1?

leducdubleuet’s picture

I can confirm that after removing the patch from MR 388 and upgrading to Drupal core 10.2.1, the file upload is working correctly in my custom web forms.

This is great news, thanks to all for your time!

kreatil’s picture

Yes, it seems to be fixed by Drupal core 10.2.1

damienmckenna’s picture

I created a new issue for replacing the validation logic with the new system: https://www.drupal.org/project/webform/issues/3413194

We could close this one as the bug is fixed in core and focus on the new plugin in the other issue.

cilefen’s picture

Status: Needs work » Closed (outdated)

raprieto changed the visibility of the branch 3409599-drupalcomponentpluginexceptionpluginnotfoundexception-the-webformfilevalidateextensions to hidden.

raprieto changed the visibility of the branch 3409599-drupalcomponentpluginexceptionpluginnotfoundexception-the-webformfilevalidateextensions to hidden.