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