Needs review
Project:
Webform REST
Version:
4.2.0
Component:
Code
Priority:
Major
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
15 Jan 2026 at 16:48 UTC
Updated:
23 Mar 2026 at 15:18 UTC
Jump to comment: Most recent
Webform REST currently does not support text_format elements. Currently it is not possible to ...
Perform GET on elements endpoint results into the following error:
The website encountered an unexpected error. Try again later.<br><br><em class="placeholder">Symfony\Component\Serializer\Exception\NotNormalizableValueException</em>: Could not normalize object of type "Drupal\Core\Url", no supporting normalizer found. in <em class="placeholder">Symfony\Component\Serializer\Serializer->normalize()</em> (line <em class="placeholder">190</em> of <em class="placeholder">/var/www/html/vendor/symfony/serializer/Serializer.php</em>). <pre class="backtrace">Symfony\Component\Serializer\Serializer->normalize(Array, 'json', Array) (Line: 179)
Symfony\Component\Serializer\Serializer->normalize(Array, 'json', Array) (Line: 179)
Symfony\Component\Serializer\Serializer->normalize(Array, 'json', Array) (Line: 179)
Symfony\Component\Serializer\Serializer->normalize(Array, 'json', Array) (Line: 179)
Symfony\Component\Serializer\Serializer->normalize(Array, 'json', Array) (Line: 140)
Symfony\Component\Serializer\Serializer->serialize(Array, 'json', Array) (Line: 159)
Drupal\rest\EventSubscriber\ResourceResponseSubscriber->renderResponseBody(Object, Object, Object, 'json') (Line: 75)
Drupal\rest\EventSubscriber\ResourceResponseSubscriber->onResponse(Object, 'kernel.response', Object)
call_user_func(Array, Object, 'kernel.response', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.response') (Line: 214)
Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object, Object, 1) (Line: 202)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 201)
Drupal\page_cache\StackMiddleware\PageCache->fetch(Object, 1, 1) (Line: 138)
Drupal\page_cache\StackMiddleware\PageCache->lookup(Object, 1, 1) (Line: 87)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 53)
Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
</pre>Perform POST on submit endpoint results in the following error (using both flat structure and object-structure) when the field is required:
{
"message": "Submitted Data contains validation errors.",
"error": {
"body": "The field @name is required."
}
}Using this form definition:
body:
'#type': text_format
'#title': Inhalt
'#required': true
'#allowed_formats':
webform: webform
webform_default: webform_defaultStart 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
fabianrichter commentedComment #3
fabianrichter commentedComment #6
andres alvarez commentedComment #7
andres alvarez commentedProblem
The REST endpoint GET /webform_rest/{id}/elements returned a 500 error when the Webform contained text_format elements.
Error
Symfony\Component\Serializer\Exception\NotNormalizableValueException: Could not normalize object of type "Drupal\Core\Url"
Root cause
The Symfony serializer tried to normalize the Webform element definition directly. text_format elements may contain Drupal\Core\Url objects in their configuration, which cannot be automatically serialized to JSON.
Solution
Updated src/Plugin/rest/resource/WebformElementsResource.php.
Added a recursive method normalizeElements(array $elements) to traverse the Webform elements.
When a Drupal\Core\Url instance is found, it is explicitly converted to a string using toString().
The get() method now normalizes the elements with this function before returning the REST response.
Tests
Added a new functional test: tests/src/Functional/WebformRestTextFormatTest.php.
The test creates a Webform with a text_format element, performs a GET request to the endpoint, and asserts a 200 OK response with valid element data.
Result
The REST endpoint now works correctly with text_format elements, resolving the serialization error.
Comment #8
fabianrichter commentedLooks really good to me and solves the issue.
One note: I was not able to apply the patch because of the different use/import order and the missing t() wrapper function around the response (
_t("Webform ID wasn't provided")and_t("Can't load webform.")).Other than that I don't see any blocker for a merge.
Thank you!
Comment #9
fabianrichter commentedI was not able to apply the
patch→ merge diff as a patch ...