You are here

protected function JsonapiResourceClassResolver::injectResourceDependencies in JSON:API Resources 8

Injects resource dependencies.

Parameters

\Drupal\jsonapi_resources\Resource\ResourceBase $resource: The JSON:API resource.

1 call to JsonapiResourceClassResolver::injectResourceDependencies()
JsonapiResourceClassResolver::getInstanceFromDefinition in src/Unstable/DependencyInjection/JsonapiResourceClassResolver.php
Returns a class instance with a given class definition.

File

src/Unstable/DependencyInjection/JsonapiResourceClassResolver.php, line 40

Class

JsonapiResourceClassResolver
Injects JSON:API resource dependencies that are internal to this module.

Namespace

Drupal\jsonapi_resources\Unstable\DependencyInjection

Code

protected function injectResourceDependencies(ResourceBase $resource) {
  $resource
    ->setResourceTypeRepository($this->container
    ->get('jsonapi.resource_type.repository'));
  $resource
    ->setResourceResponseFactory($this->container
    ->get('jsonapi_resources.resource_response_factory'));
  $resource
    ->setDocumentExtractor($this->container
    ->get('jsonapi_resources.document_extractor'));
  if ($resource instanceof EntityResourceBase) {
    $resource
      ->setEntityTypeManager($this->container
      ->get('entity_type.manager'));
    $resource
      ->setEntityAccessChecker($this->container
      ->get('jsonapi_resources.entity_access_checker'));
  }
  if ($resource instanceof EntityQueryResourceBase) {
    $resource
      ->setCacheabilityCapturingExecutor($this->container
      ->get('jsonapi_resources.entity_query_executor'));
  }
  if ($resource instanceof ResourceObjectToEntityMapperAwareInterface) {
    $resource
      ->setResourceObjectToEntityMapper($this->container
      ->get('jsonapi_resources.resource_object_to_entity_mapper'));
  }
}