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

Comments

logickal created an issue. See original summary.

logickal’s picture

First 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.

logickal’s picture

Status: Active » Needs review
logickal’s picture

Issue summary: View changes
logickal’s picture

After some further investigation, found the getInternalName() method on the ResourceType, which makes for a less janky method of matching the names up properly.

Status: Needs review » Needs work

The last submitted patch, 5: entityToJsonApi_includes_fix-3028493-5.patch, failed testing. View results

logickal’s picture

logickal’s picture

Status: Needs work » Needs review
StatusFileSize
new2.89 KB

Re-rolled patch after the latest merges to 3.x-dev fixing test failures.

e0ipso’s picture

Status: Needs review » Fixed
StatusFileSize
new1.71 KB

Changes made on commit.

  • e0ipso committed e08dae0 on 8.x-3.x authored by logickal
    Issue #3028493 by logickal, e0ipso: EntityToJsonApi includes do not...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.