Chris@0: entityTypeManager = $entity_type_manager; Chris@0: $this->entityRepository = $entity_repository; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function convert($value, $definition, $name, array $defaults) { Chris@18: $entity_type_id = $this->getEntityTypeFromDefaults($definition, $name, $defaults); Chris@0: $entity = $this->entityTypeManager->getStorage($entity_type_id)->loadRevision($value); Chris@18: Chris@18: // If the entity type is translatable, ensure we return the proper Chris@18: // translation object for the current context. Chris@18: if ($entity instanceof EntityInterface && $entity instanceof TranslatableInterface) { Chris@18: $entity = $this->entityRepository->getTranslationFromContext($entity, NULL, ['operation' => 'entity_upcast']); Chris@18: } Chris@18: Chris@18: return $entity; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function applies($definition, $name, Route $route) { Chris@0: return isset($definition['type']) && strpos($definition['type'], 'entity_revision:') !== FALSE; Chris@0: } Chris@0: Chris@0: }