You are here

public function RelationshipNormalizerValue::__construct in JSON:API 8

Instantiate a EntityReferenceNormalizerValue object.

Parameters

\Drupal\Core\Access\AccessResultInterface $relationship_access_result: The relationship access result.

RelationshipItemNormalizerValue[] $values: The normalized result.

int $cardinality: The number of fields for the field list.

array $link_context: All the objects and variables needed to generate the links for this relationship.

Overrides FieldNormalizerValue::__construct

File

src/Normalizer/Value/RelationshipNormalizerValue.php, line 55

Class

RelationshipNormalizerValue
Helps normalize relationships in compliance with the JSON API spec.

Namespace

Drupal\jsonapi\Normalizer\Value

Code

public function __construct(AccessResultInterface $relationship_access_result, array $values, $cardinality, array $link_context) {
  $this->hostEntityId = $link_context['host_entity_id'];
  $this->fieldName = $link_context['field_name'];
  $this->linkManager = $link_context['link_manager'];
  $this->resourceType = $link_context['resource_type'];
  array_walk($values, function ($field_item_value) {
    if (!$field_item_value instanceof RelationshipItemNormalizerValue) {
      throw new \RuntimeException(sprintf('Unexpected normalizer item value for this %s.', get_called_class()));
    }
  });
  parent::__construct($relationship_access_result, $values, $cardinality, 'relationships');
}