function ResourceTypeRepository::createResourceType

Same name in other branches
  1. 9 core/modules/jsonapi/src/ResourceType/ResourceTypeRepository.php \Drupal\jsonapi\ResourceType\ResourceTypeRepository::createResourceType()
  2. 10 core/modules/jsonapi/src/ResourceType/ResourceTypeRepository.php \Drupal\jsonapi\ResourceType\ResourceTypeRepository::createResourceType()
  3. 11.x core/modules/jsonapi/src/ResourceType/ResourceTypeRepository.php \Drupal\jsonapi\ResourceType\ResourceTypeRepository::createResourceType()

Creates a ResourceType value object for the given entity type + bundle.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type to create a JSON:API resource type for.

string $bundle: The entity type bundle to create a JSON:API resource type for.

Return value

\Drupal\jsonapi\ResourceType\ResourceType A JSON:API resource type.

1 call to ResourceTypeRepository::createResourceType()
ResourceTypeRepository::all in core/modules/jsonapi/src/ResourceType/ResourceTypeRepository.php
Gets all JSON:API resource types.
1 method overrides ResourceTypeRepository::createResourceType()
CountableResourceTypeRepository::createResourceType in core/modules/jsonapi/tests/modules/jsonapi_test_collection_count/src/ResourceType/CountableResourceTypeRepository.php
Creates a ResourceType value object for the given entity type + bundle.

File

core/modules/jsonapi/src/ResourceType/ResourceTypeRepository.php, line 151

Class

ResourceTypeRepository
Provides a repository of all JSON:API resource types.

Namespace

Drupal\jsonapi\ResourceType

Code

protected function createResourceType(EntityTypeInterface $entity_type, $bundle) {
    $raw_fields = $this->getAllFieldNames($entity_type, $bundle);
    $internalize_resource_type = $entity_type->isInternal();
    $fields = static::getFields($raw_fields, $entity_type, $bundle);
    if (!$internalize_resource_type) {
        $event = ResourceTypeBuildEvent::createFromEntityTypeAndBundle($entity_type, $bundle, $fields);
        $this->eventDispatcher
            ->dispatch(ResourceTypeBuildEvents::BUILD, $event);
        $internalize_resource_type = $event->resourceTypeShouldBeDisabled();
        $fields = $event->getFields();
    }
    return new ResourceType($entity_type->id(), $bundle, $entity_type->getClass(), $internalize_resource_type, static::isLocatableResourceType($entity_type, $bundle), static::isMutableResourceType($entity_type, $bundle), static::isVersionableResourceType($entity_type), $fields);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.