You are here

public function ResourceType::__construct in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/src/ResourceType/ResourceType.php \Drupal\jsonapi\ResourceType\ResourceType::__construct()
  2. 10 core/modules/jsonapi/src/ResourceType/ResourceType.php \Drupal\jsonapi\ResourceType\ResourceType::__construct()

Instantiates a ResourceType object.

Parameters

string $entity_type_id: An entity type ID.

string $bundle: A bundle.

string $deserialization_target_class: The deserialization target class.

bool $internal: (optional) Whether the resource type should be internal.

bool $is_locatable: (optional) Whether the resource type is locatable.

bool $is_mutable: (optional) Whether the resource type is mutable.

bool $is_versionable: (optional) Whether the resource type is versionable.

\Drupal\jsonapi\ResourceType\ResourceTypeField[] $fields: (optional) The resource type fields, keyed by internal field name.

null|string $type_name: The resource type name.

File

core/modules/jsonapi/src/ResourceType/ResourceType.php, line 351

Class

ResourceType
Value object containing all metadata for a JSON:API resource type.

Namespace

Drupal\jsonapi\ResourceType

Code

public function __construct($entity_type_id, $bundle, $deserialization_target_class, $internal = FALSE, $is_locatable = TRUE, $is_mutable = TRUE, $is_versionable = FALSE, array $fields = [], $type_name = NULL) {
  $this->entityTypeId = $entity_type_id;
  $this->bundle = $bundle;
  $this->deserializationTargetClass = $deserialization_target_class;
  $this->internal = $internal;
  $this->isLocatable = $is_locatable;
  $this->isMutable = $is_mutable;
  $this->isVersionable = $is_versionable;
  $this->fields = $fields;
  $this->typeName = $type_name;
  if ($type_name === NULL) {
    $this->typeName = $this->bundle === '?' ? 'unknown' : $this->entityTypeId . self::TYPE_NAME_URI_PATH_SEPARATOR . $this->bundle;
  }
  $this->fieldMapping = array_flip(array_map(function (ResourceTypeField $field) {
    return $field
      ->getPublicName();
  }, $this->fields));
}