trait ResourceObjectEntityLoaderTrait in JSON:API Hypermedia 8
Trait for loading the entity represented by a resource object.
@internal
Hierarchy
- trait \Drupal\jsonapi_hypermedia\Plugin\jsonapi_hypermedia\LinkProvider\ResourceObjectEntityLoaderTrait
File
- examples/
Plugin/ jsonapi_hypermedia/ LinkProvider/ ResourceObjectEntityLoaderTrait.php, line 13
Namespace
Drupal\jsonapi_hypermedia\Plugin\jsonapi_hypermedia\LinkProviderView source
trait ResourceObjectEntityLoaderTrait {
/**
* The entity repository.
*
* @var \Drupal\Core\Entity\EntityRepositoryInterface
*/
protected $entityRepository;
/**
* Sets the entity repository.
*
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository service.
*/
protected function setEntityRepository(EntityRepositoryInterface $entity_repository) {
$this->entityRepository = $entity_repository;
}
/**
* Gets the entity represented by the given resource object.
*
* @param \Drupal\jsonapi\JsonApiResource\ResourceObject $resource_object
* The resource object.
*
* @return \Drupal\Core\Entity\EntityInterface|null
* The represented entity or NULL if the entity does not exist.
*
* @throws \Drupal\Core\Entity\EntityStorageException
* Thrown in case the requested entity type does not support UUIDs.
*/
public function loadEntityFromResourceObject(ResourceObject $resource_object) {
return $this->entityRepository
->loadEntityByUuid($resource_object
->getResourceType(), $resource_object
->getId());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ResourceObjectEntityLoaderTrait:: |
protected | property | The entity repository. | |
ResourceObjectEntityLoaderTrait:: |
public | function | Gets the entity represented by the given resource object. | |
ResourceObjectEntityLoaderTrait:: |
protected | function | Sets the entity repository. |