Mercurial > hg > isophonics-drupal-site
diff core/lib/Drupal/Core/ParamConverter/EntityRevisionParamConverter.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | 4c8ae668cc8c |
children |
line wrap: on
line diff
--- a/core/lib/Drupal/Core/ParamConverter/EntityRevisionParamConverter.php Thu Feb 28 13:21:36 2019 +0000 +++ b/core/lib/Drupal/Core/ParamConverter/EntityRevisionParamConverter.php Thu May 09 15:33:08 2019 +0100 @@ -2,8 +2,10 @@ namespace Drupal\Core\ParamConverter; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Entity\TranslatableInterface; use Symfony\Component\Routing\Route; /** @@ -25,6 +27,8 @@ */ class EntityRevisionParamConverter implements ParamConverterInterface { + use DynamicEntityTypeParamConverterTrait; + /** * The entity type manager. * @@ -56,9 +60,16 @@ * {@inheritdoc} */ public function convert($value, $definition, $name, array $defaults) { - list (, $entity_type_id) = explode(':', $definition['type'], 2); + $entity_type_id = $this->getEntityTypeFromDefaults($definition, $name, $defaults); $entity = $this->entityTypeManager->getStorage($entity_type_id)->loadRevision($value); - return $this->entityRepository->getTranslationFromContext($entity); + + // 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; } /**