You are here

public function FieldNormalizerValue::__construct in JSON:API 8

Instantiate a FieldNormalizerValue object.

Parameters

\Drupal\Core\Access\AccessResultInterface $field_access_result: The field access result.

\Drupal\jsonapi\Normalizer\Value\FieldItemNormalizerValue[] $values: The normalized result.

int $cardinality: The cardinality of the field list.

string $property_type: The property type of the field: 'attributes' or 'relationships'.

2 calls to FieldNormalizerValue::__construct()
IncludeOnlyRelationshipNormalizerValue::__construct in src/Normalizer/Value/IncludeOnlyRelationshipNormalizerValue.php
Instantiate a IncludeOnlyRelationshipNormalizerValue object.
RelationshipNormalizerValue::__construct in src/Normalizer/Value/RelationshipNormalizerValue.php
Instantiate a EntityReferenceNormalizerValue object.
2 methods override FieldNormalizerValue::__construct()
IncludeOnlyRelationshipNormalizerValue::__construct in src/Normalizer/Value/IncludeOnlyRelationshipNormalizerValue.php
Instantiate a IncludeOnlyRelationshipNormalizerValue object.
RelationshipNormalizerValue::__construct in src/Normalizer/Value/RelationshipNormalizerValue.php
Instantiate a EntityReferenceNormalizerValue object.

File

src/Normalizer/Value/FieldNormalizerValue.php, line 58

Class

FieldNormalizerValue
Helps normalize fields in compliance with the JSON API spec.

Namespace

Drupal\jsonapi\Normalizer\Value

Code

public function __construct(AccessResultInterface $field_access_result, array $values, $cardinality, $property_type) {
  assert($property_type === 'attributes' || $property_type === 'relationships');
  $this
    ->setCacheability(static::mergeCacheableDependencies(array_merge([
    $field_access_result,
  ], $values)));
  $this->values = $values;
  $this->includes = array_map(function ($value) {
    if (!$value instanceof RelationshipItemNormalizerValue) {
      return NULL;
    }
    return $value
      ->getInclude();
  }, $values);
  $this->includes = array_filter($this->includes);
  $this->cardinality = $cardinality;
  $this->propertyType = $property_type;
}