Problem/Motivation
We have custom code that leverages the entity.to_jsonapi service to build a composite document using specific includes parameters. We found that with the latest version of JsonAPI_Extras we were getting InvalidArgumentExceptions being thrown because the service was passing in our overridden field names without properly transforming them back to the original value (i.e. the override field name of 'layout' from the include statement was being passed instead of 'field_layout').
This may be me being opinionated, but I feel like Extras should respect its own overrides if this service is being used.
Proposed resolution
Add handling for includes in either overridden or non-overridden formats.
Remaining tasks
Tests would probably be good.
User interface changes
N/A
API changes
N/A
Data model changes
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | interdiff.txt | 1.71 KB | e0ipso |
| #8 | 3028493-8.jsonapi_extras.EntityToJsonApi-includes-do-not-honor-overridden-fields.patch | 2.89 KB | logickal |
| #5 | entityToJsonApi_includes_fix-3028493-5.patch | 3.19 KB | logickal |
| #2 | entityToJsonApi_includes_fix-3028493-2.patch | 3.21 KB | logickal |
Comments
Comment #2
logickal commentedFirst attempt at a patch. Since both serialize() and normalize() have similar requirements, I extracted this logic into a new prepareDocument() method. I also noticed the issue with JsonApiDocumentTopLevel now needing a LinkCollection passed as argument 3 as posted in #3027768: Argument 3 passed to Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel::__construct() must be an instance of Drupal\jsonapi\JsonApiResource\LinkCollection, so that fix is included here as well.
Comment #3
logickal commentedComment #4
logickal commentedComment #5
logickal commentedAfter some further investigation, found the getInternalName() method on the ResourceType, which makes for a less janky method of matching the names up properly.
Comment #7
logickal commented@e0ipso - The failing tests are the same
http://:/malformation that was seen in #3027768: Argument 3 passed to Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel::__construct() must be an instance of Drupal\jsonapi\JsonApiResource\LinkCollectionComment #8
logickal commentedRe-rolled patch after the latest merges to 3.x-dev fixing test failures.
Comment #9
e0ipsoChanges made on commit.