You are here

public function Relationship::__construct in JSON:API 8

Relationship constructor.

Parameters

\Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface $resource_type_repository: The JSON API resource type repository.

string $field_name: The name of the relationship.

\Drupal\jsonapi\Resource\EntityCollection $entities: A collection of entities.

\Drupal\Core\Entity\EntityInterface $host_entity: The host entity.

\Drupal\Core\Access\AccessResultInterface $view_access: The 'view' field access result. (This value object is only ever used for normalization, and hence only for 'view' access.

int $cardinality: The relationship cardinality.

string $target_key: The property name of the relationship id.

array $entity_list_metadata: An array of additional properties stored by the field and that will be added to the meta in the relationship.

File

src/Normalizer/Relationship.php, line 84

Class

Relationship
Represents a relationship between resources.

Namespace

Drupal\jsonapi\Normalizer

Code

public function __construct(ResourceTypeRepositoryInterface $resource_type_repository, $field_name, EntityCollection $entities, EntityInterface $host_entity, AccessResultInterface $view_access, $cardinality = FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, $target_key = 'target_id', array $entity_list_metadata = []) {
  $this->resourceTypeRepository = $resource_type_repository;
  $this->propertyName = $field_name;
  $this->cardinality = $cardinality;
  $this->hostEntity = $host_entity;
  $this
    ->setCacheability($view_access);
  $this->items = [];
  foreach ($entities as $key => $entity) {
    $this->items[] = new RelationshipItem($resource_type_repository, $entity, $this, $target_key, $entity_list_metadata[$key]);
  }
}