Problem/Motivation
From See #2800873-124: Add XML GET REST test coverage, work around XML encoder quirks:
But for XML [serialization of the ImageStyle config entity], this is the response you get:
Fstring(2801) "The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">DOMException</em>: Invalid Character Error in <em class="placeholder">DOMDocument->createElement()</em> (line <em class="placeholder">452</em> of <em class="placeholder">vendor/symfony/serializer/Encoder/XmlEncoder.php</em>). <pre class="backtrace">Symfony\Component\Serializer\Encoder\XmlEncoder->appendNode(Object, Array, '574d9c11-33ec-4fa7-9a6b-6783600c9cfa') (Line: 408) Symfony\Component\Serializer\Encoder\XmlEncoder->buildXml(Object, Array) (Line: 490) Symfony\Component\Serializer\Encoder\XmlEncoder->selectNodeType(Object, Array) (Line: 456) Symfony\Component\Serializer\Encoder\XmlEncoder->appendNode(Object, Array, 'effects') (Line: 408) Symfony\Component\Serializer\Encoder\XmlEncoder->buildXml(Object, Array, 'response') (Line: 65) Symfony\Component\Serializer\Encoder\XmlEncoder->encode(Array, 'xml', Array) (Line: 60) Drupal\serialization\Encoder\XmlEncoder->encode(Array, 'xml', Array) (Line: 38) Symfony\Component\Serializer\Encoder\ChainEncoder->encode(Array, 'xml', Array) (Line: 233) Symfony\Component\Serializer\Serializer->encode(Array, 'xml', Array) (Line: 118) Symfony\Component\Serializer\Serializer->serialize(Array, 'xml') (Line: 156) Drupal\rest\EventSubscriber\ResourceResponseSubscriber->Drupal\rest\EventSubscriber\{closure}() (Line: 574) Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 157) Drupal\rest\EventSubscriber\ResourceResponseSubscriber->renderResponseBody(Object, Object, Object, 'xml') (Line: 74) Drupal\rest\EventSubscriber\ResourceResponseSubscriber->onResponse(Object, 'kernel.response', Object) (Line: 108) Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.response', Object) (Line: 193) Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object, Object, 1) (Line: 175) Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68) 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: 656) Drupal\Core\DrupalKernel->handle(Object) (Line: 19) </pre>"The root cause:
$this->effectUuid => [ 'uuid' => $this->effectUuid, 'id' => 'image_scale_and_crop', 'weight' => 0, 'data' => [ 'width' => 120, 'height' => 121, ], ],i.e. a UUID is being used as a key for an array, which means that the XML encoder will try to map this to an XML tag (element). And dashes aren't allowed in XML tag/element names, hence this exception.
I don't see a way to work around this. But it also shouldn't hold up everything else. So created a new issue for that: #2905655: XML encoder does not support UUIDs as keys: makes ImageStyle config entity XML serialization crash.
Therefore for now including stub test coverage.
Proposed resolution
TBD
Remaining tasks
TBD
User interface changes
None.
API changes
TBD
Data model changes
TBD
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 2905655-3.patch | 2.49 KB | wim leers |
Comments
Comment #2
wim leers#2800873: Add XML GET REST test coverage, work around XML encoder quirks is in, now we can continue here.
Comment #3
wim leersThis is what we need to achieve.
Comment #4
wim leersUpdated IS by lifting the contents of the comment where this was first discovered.
Comment #5
wim leersI see only two possible ways to solve this:
ImageStyleconfig entities. This is a data model change. Theoretically a BC break, but an automated update path could be provided. Plus, it's possible there are contrib/custom config entities that have a similar data structure. It should not be necessary for the data structure to disallow UUIDs as keys just because XML can't encode it.af73797f-15d3-4140-b684-d6bf1c7897feto<uuid value="af73797f-15d3-4140-b684-d6bf1c7897fe">or something like that. But our XML normalizer is blissfully unaware of attributes, so not sure how yet. Also, the UUID is repeated in the map itself, so it'd end up looking silly.So perhaps it is best to go with option 1. Because
is pretty silly.
Moving this to the
image.modulecomponent to get feedback.Comment #18
smustgrave commentedThank you for creating this issue to improve Drupal.
We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.
Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!