There's only one use:
\Drupal\jsonapi\Resource\EntityResource::buildWrappedResponse() does this:
protected function buildWrappedResponse($data, $response_code = 200, array $headers = []) {
return new ResourceResponse(new DocumentWrapper($data), $response_code, $headers);
}
DocumentWrapper(Interface) has zero meaningful documentation, nor does it refer back to http://jsonapi.org/format — which would have been the indirect way of figuring out why this exists and what purpose it serves.
I suspect it's a wrapper for normalized entity objects (or any normalized data, really), to correspond to http://jsonapi.org/format/#document-structure. But if that's the case, it's extremely confusing that there's only a getData() method and not also getErrors() and getMeta() (at minimum, not even talking about links or jsonapi or included).
Comments
Comment #2
wim leersI also just realized part of the reason why I have a hard time understanding this at all:
\Drupal\jsonapi\Resource\DocumentWrapper(Interface), but the corresponding (de)normalizer is called\Drupal\jsonapi\Normalizer\DocumentRootNormalizer!This should be made consistent.
Also, I think
JsonApiDocumentandJsonApiDocumentNormalizerwould be a whole lot clearer. Or evenJsonApiDocumentTopLevelandJsonApiDocumentTopLevelNormalizer.This would clearly correspond 1:1 to http://jsonapi.org/format/#document-top-level.Comment #3
e0ipso+1 to
JsonApiDocumentTopLevelandJsonApiDocumentTopLevelNormalizer.Comment #4
wim leersAlright!
Comment #5
wim leersDone.
Did what we described in #2 + #3. Plus:
\Drupal\jsonapi\Normalizer\RelationshipNormalizerno longer gets this injected, because it didn't use it anyway!Comment #7
wim leersFixing a few nitpicky oversights.
Comment #8
wim leersI totally missed
DocumentRootNormalizerTest.Comment #12
wim leersOh hah apparently there's also
\Drupal\Tests\jsonapi\Unit\Normalizer\DocumentRootNormalizerTest— #8 fixed the kernel test.Comment #14
wim leersTurns out
\Drupal\Tests\jsonapi\Unit\Normalizer\ConfigEntityNormalizerTestwas incredibly wrong, and hence I'm required to update it here.Comment #15
wim leersThis is blocking #2838630-5: Remove the concept of "enabledness" from the JSON API module, rely on the Entity Access API instead.
Comment #16
e0ipsoMerging.
Comment #18
e0ipso