You are here

protected function EntityParameterFactory::doTransform in JSON-RPC 2.x

Same name and namespace in other branches
  1. 8 src/ParameterFactory/EntityParameterFactory.php \Drupal\jsonrpc\ParameterFactory\EntityParameterFactory::doTransform()

File

src/ParameterFactory/EntityParameterFactory.php, line 77

Class

EntityParameterFactory
A factory to create loaded entities from entity type & UUID user input.

Namespace

Drupal\jsonrpc\ParameterFactory

Code

protected function doTransform($data, Context $context = NULL) {
  try {
    if ($entity = $this->entityRepository
      ->loadEntityByUuid($data['type'], $data['uuid'])) {
      return $entity;
    }
    throw JsonRpcException::fromError(Error::invalidParams('The requested entity could not be found.'));
  } catch (EntityStorageException $e) {
    throw JsonRpcException::fromError(Error::invalidParams('This entity type is not supported. Error: ' . $e
      ->getMessage()));
  }
}