function ResourceObjectNormalizationCacher::saveOnTerminate

Same name in other branches
  1. 9 core/modules/jsonapi/src/EventSubscriber/ResourceObjectNormalizationCacher.php \Drupal\jsonapi\EventSubscriber\ResourceObjectNormalizationCacher::saveOnTerminate()
  2. 8.9.x core/modules/jsonapi/src/EventSubscriber/ResourceObjectNormalizationCacher.php \Drupal\jsonapi\EventSubscriber\ResourceObjectNormalizationCacher::saveOnTerminate()
  3. 11.x core/modules/jsonapi/src/EventSubscriber/ResourceObjectNormalizationCacher.php \Drupal\jsonapi\EventSubscriber\ResourceObjectNormalizationCacher::saveOnTerminate()

Adds a normalization to be cached after the response has been sent.

Parameters

\Drupal\jsonapi\JsonApiResource\ResourceObject $object: The resource object for which to generate a cache item.

array $normalization_parts: The normalization parts to cache.

File

core/modules/jsonapi/src/EventSubscriber/ResourceObjectNormalizationCacher.php, line 149

Class

ResourceObjectNormalizationCacher
Caches entity normalizations after the response has been sent.

Namespace

Drupal\jsonapi\EventSubscriber

Code

public function saveOnTerminate(ResourceObject $object, array $normalization_parts) {
    assert(array_keys($normalization_parts) === [
        static::RESOURCE_CACHE_SUBSET_BASE,
        static::RESOURCE_CACHE_SUBSET_FIELDS,
    ]);
    $resource_type = $object->getResourceType();
    $key = $resource_type->getTypeName() . ':' . $object->getId();
    $this->toCache[$key] = [
        $object,
        $normalization_parts,
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.