Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
After enabling the REST resource for Webform submission and enabling all HTTP methods, request formats and authentication providers, creating a test submission and trying to access from the endpoint /admin/structure/webform/manage/demo_application/submission/1?_format=json , I get the following error with the stack trace:
The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\rest\Plugin\rest\resource\EntityResource::get() must implement interface Drupal\Core\Entity\EntityInterface, string given in Drupal\rest\Plugin\rest\resource\EntityResource->get() (line 103 of core/modules/rest/src/Plugin/rest/resource/EntityResource.php).
Drupal\rest\Plugin\rest\resource\EntityResource->get('demo_application', Object, NULL, Object)
call_user_func_array(Array, Array) (Line: 133)
Drupal\rest\RequestHandler->handle(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 652)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
I tested this on multiple environments and reproduced this with a clean install of Drupal 8.2.7 and enabling only the Web Services modules (HAL, HTTP Basic Auth., RESTful Web Services, and Serialization), the REST-UI module, and the Webforms module.
Comment | File | Size | Author |
---|---|---|---|
#2 | REST resources Webform Demo Site.png | 220.81 KB | jrockowitz |
#2 | error_accessing_webform-2865549-2.patch | 868 bytes | jrockowitz |
|
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe attached patch gets the below endpoints working...
Someone still needs to setup a REST normalizer to handler webform submission data. The normalizer is definitely going to require some test coverage.
@see \Drupal\webform\WebformSubmissionForm::validateValues for how to validate submission data during PATCH operation.
Comment #3
hanoiiIs there any REST support at all? I actually tries submitting a webform submission to /entity/webform_submission and had different issues, but one I am not sure how to overcome is that if I pass on the 'data' variable, I get a fatal error:
message : "A fatal error occurred: Field data is unknown."
I debugged this and is indeed an issue as the default EntityNormalizer.php is being used.
I guess a WebformSumissionEntityNormalizer.php will have to be created, both as a normalizer and denormalizer for creating values.
I have an OK experience with normalizers, not that much with denormalizers or everything that it should do, I wonder if we could make a simple one to start with.
Will see if I can get to work on this, but I think for the time being I will create a custom rest resource to handle this myself.
Comment #4
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedSomeone needs to start working on the normalizer. Fortunately, there is a \Drupal\webform\WebformSubmissionForm::submitValues which should make handling the submitted data really easy.
Comment #5
imclean CreditAttribution: imclean commented@hanoii for a basic solution to submitting webforms you can use Webform REST. This is very simple and doesn't take into account all field types, such as file field.
See also How to programmatically create a submission.
Comment #6
hanoii@imclean interesting, very similar to what i was planning on doing. Will take a look, I might give the normalizer a try though to see if I can have something initial working for webform
Comment #7
hanoiiI have been doing some work with a normalizer. It gets tricky as the webform submission has its own form handler and all and it gets trickier using the default /entity/webform_submission core's resource with accesses and all. I know I can make it work somehow but it's gonna be overriding a lot of logic only for that.
I think the approach @imclean took is better. @jrockowitz would you me interested in trying to merge that into webform, providing its one resource endpoint or you had something else in mind for something like this?
Comment #8
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI am open to merging the webform_rest.module once it has test coverage.
Comment #9
imclean CreditAttribution: imclean commentedAdding tests should be the next step.
In addition, I think it should probably support some other Webform features, such as file fields and confirmation settings. Currently after submitting a webform only the submission ID is returned.
There are 2 open feature requests in the issue queue. I don't have much time to work on these at the moment.
Comment #10
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI am not going to commit the partial patch since this issue is addressed via Webform REST module.