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}| Comment | File | Size | Author |
|---|---|---|---|
| #28 | 3409599-28.mr388.webform_file_validate_extensions-plugin.patch | 3.29 KB | jrb |
Issue fork webform-3409599
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
Comment #2
greatmatter commentedComment #3
cilefen commentedSee also https://drupal.stackexchange.com/questions/317946/webform-file-upload-fa... with questions, some answered.
Comment #4
greatmatter commentedWhile 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.
Comment #5
greatmatter commented@cilefen thank you. I don't have anything like that in the config folder, but I do see the following in my site filebase:
Comment #6
ryo ichiyama commentedI 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.
Comment #7
cilefen commentedAre any patches installed on these sites?
Comment #8
cilefen commentedAlso, please post the YAML of a simple form that exhibits the bug.
Comment #9
cilefen commentedI can’t reproduce this by intuiting the steps.
Comment #10
ryo ichiyama commentedHello.
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.
Comment #11
jonathanhulet commentedHello
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
Comment #12
benaboki commentedI 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: ...Comment #13
benaboki commented#4 allows submissions to go through so I have it as a temporary fix as well. Thanks @greatmatter
Comment #14
cilefen commentedIs this problem analogous to #3409317: Core version 10.2 imce error?
Comment #15
greatmatter commented@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
Comment #16
cilefen commentedI said "analogous", not "caused by".
Anyway, we just got hit with this one so I have a form that reproduce this now.
Comment #17
ankithashetty+1 to this issue.
For now tried the #4 suggestion as a workaround.
Comment #18
cilefen commentedI think the fact that no function exists of the name webform_file_validate_extensions is the problem here.
Comment #19
sakthi_dev commentedI 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.
Comment #20
cilefen commentedI would go so far as to make this a critical for this module, because file uploads are a major feature.
Comment #21
damienmckennaI 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.
Comment #22
cilefen commentedWhat about the element in #10?
Comment #23
damienmckennaJust cross referencing the original core issue: #3221793: Move file upload validation from file.module to constraint validators
Comment #24
damienmckennaFYI 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().
Comment #25
damienmckennaI opened a new core issue about this: #3410126: File validation logic from #3221793 broke backwards compatibility
Comment #27
sakthi_dev commentedUpdated the code as per comment #19. Please review.
Comment #28
jrbThe changes in MR 388 fixed the issue for us. Attached is a patch with the diffs as of today.
Comment #29
raffie commentedI 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_..."
}
}
}
Comment #30
damienmckenna@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...
Comment #31
jwnukoski commentedPatch 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:
Comment #32
ethangeorgi commentedPatch worked for us, too. Thank you!
Drupal 10.2.0
PHP 8.1.26
MariaDB 10.4.25
drupal/webform 6.2.2
Comment #33
leducdubleuet commentedPatch worked for us as well, thank you very much!
Comment #34
jrockowitz commentedI 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
Comment #35
cilefen commentedThe core issue is fixed. Is this even still happening on 10.2.x?
Comment #36
leducdubleuet commentedAs of this morning, the patch is still needed with 10.2 for the file upload to work properly so yes this is still happening.
Comment #37
leducdubleuet commentedI 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 :
But we still have :
Comment #38
sakthi_dev commentedJust 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.
Comment #39
cilefen commentedJust to be clear, I am referring to testing with 10.2.x, the branch head, not with 10.2.0 release.
Comment #40
damienmckennaWith the core change does this mean that the validation logic in Webform should be rewritten to be a constraint instead of just a function?
Comment #41
cilefen commentedIs this fixed by 10.2.1?
Comment #42
leducdubleuet commentedI 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!
Comment #43
kreatil commentedYes, it seems to be fixed by Drupal core 10.2.1
Comment #44
damienmckennaI 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.
Comment #45
cilefen commented