Loading core/modules/jsonapi/src/EventSubscriber/ResourceObjectNormalizationCacher.php +1 −1 Original line number Diff line number Diff line Loading @@ -164,7 +164,7 @@ protected function set(ResourceObject $object, array $normalization_parts) { protected static function generateLookupRenderArray(ResourceObject $object) { return [ '#cache' => [ 'keys' => [$object->getResourceType()->getTypeName(), $object->getId()], 'keys' => [$object->getResourceType()->getTypeName(), $object->getId(), $object->getLanguage()->getId()], 'bin' => 'jsonapi_normalizations', ], ]; Loading core/modules/jsonapi/src/JsonApiResource/ResourceObject.php +28 −2 Original line number Diff line number Diff line Loading @@ -9,6 +9,8 @@ use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\RevisionableInterface; use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\TypedData\TypedDataInternalPropertiesHelper; use Drupal\Core\Url; use Drupal\jsonapi\JsonApiSpec; Loading Loading @@ -60,6 +62,13 @@ class ResourceObject implements CacheableDependencyInterface, ResourceIdentifier */ protected $links; /** * The resource language. * * @var \Drupal\Core\Language\LanguageInterface */ protected $language; /** * ResourceObject constructor. * Loading @@ -76,8 +85,10 @@ class ResourceObject implements CacheableDependencyInterface, ResourceIdentifier * An array of the resource object's fields, keyed by public field name. * @param \Drupal\jsonapi\JsonApiResource\LinkCollection $links * The links for the resource object. * @param \Drupal\Core\Language\LanguageInterface|null $language * (optional) The resource language. */ public function __construct(CacheableDependencyInterface $cacheability, ResourceType $resource_type, $id, $revision_id, array $fields, LinkCollection $links) { public function __construct(CacheableDependencyInterface $cacheability, ResourceType $resource_type, $id, $revision_id, array $fields, LinkCollection $links, LanguageInterface $language = NULL) { assert(is_null($revision_id) || $resource_type->isVersionable()); $this->setCacheability($cacheability); $this->resourceType = $resource_type; Loading @@ -85,6 +96,10 @@ public function __construct(CacheableDependencyInterface $cacheability, Resource $this->versionIdentifier = $revision_id ? 'id:' . $revision_id : NULL; $this->fields = $fields; $this->links = $links->withContext($this); // If the specified language empty it falls back the same way as in the entity system // @see \Drupal\Core\Entity\EntityBase::language() $this->language = $language ?: new Language(['id' => LanguageInterface::LANGCODE_NOT_SPECIFIED]); } /** Loading @@ -109,7 +124,8 @@ public static function createFromEntity(ResourceType $resource_type, EntityInter $entity->uuid(), $resource_type->isVersionable() && $entity instanceof RevisionableInterface ? $entity->getRevisionId() : NULL, static::extractFieldsFromEntity($resource_type, $entity), static::buildLinksFromEntity($resource_type, $entity, $links ?: new LinkCollection([])) static::buildLinksFromEntity($resource_type, $entity, $links ?: new LinkCollection([])), $entity->language() ); } Loading Loading @@ -153,6 +169,16 @@ public function getFields() { return $this->fields; } /** * Gets the ResourceObject's language. * * @return \Drupal\Core\Language\LanguageInterface * The resource language. */ public function getLanguage(): LanguageInterface { return $this->language; } /** * Gets the ResourceObject's links. * Loading core/modules/jsonapi/tests/src/Functional/NodeTest.php +3 −2 Original line number Diff line number Diff line Loading @@ -377,9 +377,10 @@ protected function assertCacheableNormalizations(): void { // Save the entity to invalidate caches. $this->entity->save(); $uuid = $this->entity->uuid(); $language = $this->entity->language()->getId(); $cache = \Drupal::service('render_cache')->get([ '#cache' => [ 'keys' => ['node--camelids', $uuid], 'keys' => ['node--camelids', $uuid, $language], 'bin' => 'jsonapi_normalizations', ], ]); Loading Loading @@ -415,7 +416,7 @@ protected function assertCacheableNormalizations(): void { protected function assertNormalizedFieldsAreCached(array $field_names): void { $cache = \Drupal::service('render_cache')->get([ '#cache' => [ 'keys' => ['node--camelids', $this->entity->uuid()], 'keys' => ['node--camelids', $this->entity->uuid(), $this->entity->language()->getId()], 'bin' => 'jsonapi_normalizations', ], ]); Loading Loading
core/modules/jsonapi/src/EventSubscriber/ResourceObjectNormalizationCacher.php +1 −1 Original line number Diff line number Diff line Loading @@ -164,7 +164,7 @@ protected function set(ResourceObject $object, array $normalization_parts) { protected static function generateLookupRenderArray(ResourceObject $object) { return [ '#cache' => [ 'keys' => [$object->getResourceType()->getTypeName(), $object->getId()], 'keys' => [$object->getResourceType()->getTypeName(), $object->getId(), $object->getLanguage()->getId()], 'bin' => 'jsonapi_normalizations', ], ]; Loading
core/modules/jsonapi/src/JsonApiResource/ResourceObject.php +28 −2 Original line number Diff line number Diff line Loading @@ -9,6 +9,8 @@ use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\RevisionableInterface; use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\TypedData\TypedDataInternalPropertiesHelper; use Drupal\Core\Url; use Drupal\jsonapi\JsonApiSpec; Loading Loading @@ -60,6 +62,13 @@ class ResourceObject implements CacheableDependencyInterface, ResourceIdentifier */ protected $links; /** * The resource language. * * @var \Drupal\Core\Language\LanguageInterface */ protected $language; /** * ResourceObject constructor. * Loading @@ -76,8 +85,10 @@ class ResourceObject implements CacheableDependencyInterface, ResourceIdentifier * An array of the resource object's fields, keyed by public field name. * @param \Drupal\jsonapi\JsonApiResource\LinkCollection $links * The links for the resource object. * @param \Drupal\Core\Language\LanguageInterface|null $language * (optional) The resource language. */ public function __construct(CacheableDependencyInterface $cacheability, ResourceType $resource_type, $id, $revision_id, array $fields, LinkCollection $links) { public function __construct(CacheableDependencyInterface $cacheability, ResourceType $resource_type, $id, $revision_id, array $fields, LinkCollection $links, LanguageInterface $language = NULL) { assert(is_null($revision_id) || $resource_type->isVersionable()); $this->setCacheability($cacheability); $this->resourceType = $resource_type; Loading @@ -85,6 +96,10 @@ public function __construct(CacheableDependencyInterface $cacheability, Resource $this->versionIdentifier = $revision_id ? 'id:' . $revision_id : NULL; $this->fields = $fields; $this->links = $links->withContext($this); // If the specified language empty it falls back the same way as in the entity system // @see \Drupal\Core\Entity\EntityBase::language() $this->language = $language ?: new Language(['id' => LanguageInterface::LANGCODE_NOT_SPECIFIED]); } /** Loading @@ -109,7 +124,8 @@ public static function createFromEntity(ResourceType $resource_type, EntityInter $entity->uuid(), $resource_type->isVersionable() && $entity instanceof RevisionableInterface ? $entity->getRevisionId() : NULL, static::extractFieldsFromEntity($resource_type, $entity), static::buildLinksFromEntity($resource_type, $entity, $links ?: new LinkCollection([])) static::buildLinksFromEntity($resource_type, $entity, $links ?: new LinkCollection([])), $entity->language() ); } Loading Loading @@ -153,6 +169,16 @@ public function getFields() { return $this->fields; } /** * Gets the ResourceObject's language. * * @return \Drupal\Core\Language\LanguageInterface * The resource language. */ public function getLanguage(): LanguageInterface { return $this->language; } /** * Gets the ResourceObject's links. * Loading
core/modules/jsonapi/tests/src/Functional/NodeTest.php +3 −2 Original line number Diff line number Diff line Loading @@ -377,9 +377,10 @@ protected function assertCacheableNormalizations(): void { // Save the entity to invalidate caches. $this->entity->save(); $uuid = $this->entity->uuid(); $language = $this->entity->language()->getId(); $cache = \Drupal::service('render_cache')->get([ '#cache' => [ 'keys' => ['node--camelids', $uuid], 'keys' => ['node--camelids', $uuid, $language], 'bin' => 'jsonapi_normalizations', ], ]); Loading Loading @@ -415,7 +416,7 @@ protected function assertCacheableNormalizations(): void { protected function assertNormalizedFieldsAreCached(array $field_names): void { $cache = \Drupal::service('render_cache')->get([ '#cache' => [ 'keys' => ['node--camelids', $this->entity->uuid()], 'keys' => ['node--camelids', $this->entity->uuid(), $this->entity->language()->getId()], 'bin' => 'jsonapi_normalizations', ], ]); Loading