protected function ResourceTestBase::normalize in JSON:API 8.2
Same name and namespace in other branches
- 8 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.
4 calls to ResourceTestBase::normalize()
- ResourceTestBase::testPatchIndividual in tests/
src/ Functional/ ResourceTestBase.php - Tests PATCHing an individual resource, plus edge cases to ensure good DX.
- ResourceTestBase::testPostIndividual in tests/
src/ Functional/ ResourceTestBase.php - Tests POSTing an individual resource, plus edge cases to ensure good DX.
- UserTest::testPatchDxForSecuritySensitiveBaseFields in tests/
src/ Functional/ UserTest.php - Tests PATCHing security-sensitive base fields of the logged in account.
- UserTest::testPatchSecurityOtherUser in tests/
src/ Functional/ UserTest.php - Tests PATCHing security-sensitive base fields to change other users.
File
- tests/
src/ Functional/ ResourceTestBase.php, line 379
Class
- ResourceTestBase
- Subclass this for every JSON:API resource type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
protected function normalize(EntityInterface $entity, Url $url) {
$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();
}