function ResourceTestBase::normalize
Same name in other branches
- 9 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::normalize()
- 8.9.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::normalize()
- 10 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::normalize()
Generates a JSON:API normalization for the given entity.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity to generate a JSON:API normalization for.
\Drupal\Core\Url $url: The URL to use as the "self" link.
Return value
array The JSON:API normalization for the given entity.
3 calls to ResourceTestBase::normalize()
- ResourceTestBase::doTestPatchIndividual in core/
modules/ jsonapi/ tests/ src/ Functional/ ResourceTestBase.php - Tests PATCHing an individual resource, plus edge cases to ensure good DX.
- ResourceTestBase::doTestPostIndividual in core/
modules/ jsonapi/ tests/ src/ Functional/ ResourceTestBase.php - Tests POSTing an individual resource, plus edge cases to ensure good DX.
- UserTest::testPatchSecurityOtherUser in core/
modules/ jsonapi/ tests/ src/ Functional/ UserTest.php - Tests PATCHing security-sensitive base fields to change other users.
File
-
core/
modules/ jsonapi/ tests/ src/ Functional/ ResourceTestBase.php, line 376
Class
- ResourceTestBase
- Subclass this for every JSON:API resource type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
protected function normalize(EntityInterface $entity, Url $url) {
// Don't use cached normalizations in tests.
$this->container
->get('cache.jsonapi_normalizations')
->deleteAll();
$self_link = new Link(new CacheableMetadata(), $url, 'self');
$resource_type = $this->container
->get('jsonapi.resource_type.repository')
->getByTypeName(static::$resourceTypeName);
$doc = new JsonApiDocumentTopLevel(new ResourceObjectData([
ResourceObject::createFromEntity($resource_type, $entity),
], 1), new NullIncludedData(), new LinkCollection([
'self' => $self_link,
]));
return $this->serializer
->normalize($doc, 'api_json', [
'resource_type' => $resource_type,
'account' => $this->account,
])
->getNormalization();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.