entityRepository = $entity_repository; } /** * {@inheritdoc} */ public static function create(ParameterDefinitionInterface $definition, ContainerInterface $container) { return new static( $definition, $container->get('jsonrpc.schema_validator'), $container->get('entity.repository') ); } /** * {@inheritdoc} */ public static function schema(ParameterDefinitionInterface $parameter_definition = NULL) { return [ 'type' => 'object', 'properties' => [ 'type' => ['type' => 'string'], 'uuid' => ['type' => 'string'], ], ]; } /** * {@inheritdoc} */ public function getOutputValidator() { return new InstanceofValidator(EntityInterface::class); } /** * {@inheritdoc} */ 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())); } } }