You are here

public function RelationshipItemNormalizerValue::__construct in JSON:API 8

Instantiates a RelationshipItemNormalizerValue object.

Parameters

array $values: The values.

\Drupal\Core\Cache\CacheableDependencyInterface $values_cacheability: The cacheability of the normalized result. This cacheability is not part of $values because field items are normalized by Drupal core's serialization system, which was never designed with cacheability in mind. FieldItemNormalizer::normalize() must catch the out-of-band bubbled cacheability and then passes it to this value object.

string $resource: The resource type of the target entity.

\Drupal\jsonapi\Normalizer\Value\EntityNormalizerValue|\Drupal\jsonapi\Normalizer\Value\JsonApiDocumentTopLevelNormalizerValue|\Drupal\jsonapi\Normalizer\Value\HttpExceptionNormalizerValue|null $include: The included normalized entity, or NULL.

Overrides FieldItemNormalizerValue::__construct

File

src/Normalizer/Value/RelationshipItemNormalizerValue.php, line 46

Class

RelationshipItemNormalizerValue
Helps normalize relationship items in compliance with the JSON API spec.

Namespace

Drupal\jsonapi\Normalizer\Value

Code

public function __construct(array $values, CacheableDependencyInterface $values_cacheability, $resource, $include) {
  assert($include === NULL || $include instanceof EntityNormalizerValue || $include instanceof JsonApiDocumentTopLevelNormalizerValue || $include instanceof HttpExceptionNormalizerValue);
  parent::__construct($values, $values_cacheability);
  if ($include !== NULL) {
    $this
      ->setCacheability(static::mergeCacheableDependencies([
      $include,
      $values_cacheability,
    ]));
  }
  $this->resource = $resource;
  $this->include = $include;
}