You are here

public function StaticDataDefinitionExtractor::extract in JSON:API Schema 8

Extracts the data definition information for an entity type and bundle.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type to extract the data definitions for.

string $bundle: The entity bundle.

Return value

\Drupal\Core\TypedData\DataDefinition|\Drupal\Core\TypedData\MapDataDefinition The collection of data definitions, one for each field.

Throws

\LogicException If the entity type is neither configuration or content.

1 call to StaticDataDefinitionExtractor::extract()
StaticDataDefinitionExtractor::extractField in src/StaticDataDefinitionExtractor.php

File

src/StaticDataDefinitionExtractor.php, line 85

Class

StaticDataDefinitionExtractor
Extracts the data definition for entities of an entity type.

Namespace

Drupal\jsonapi_schema

Code

public function extract(EntityTypeInterface $entity_type, $bundle) {
  $data_type = sprintf('entity:%s:%s', $entity_type
    ->id(), $bundle);
  if (isset($this->definitions[$data_type])) {
    return $this->definitions[$data_type];
  }
  if ($entity_type instanceof ContentEntityTypeInterface) {
    $definition = $this
      ->extractContentEntityType($entity_type, $bundle);
  }
  else {
    if ($entity_type instanceof ConfigEntityTypeInterface) {
      $definition = $this
        ->extractConfigEntityType($entity_type, $bundle);
    }
    else {
      throw new \LogicException('Only configuration and content entities are supported.');
    }
  }
  $this->definitions[$data_type] = $definition;
  return $definition;
}