Mercurial > hg > isophonics-drupal-site
comparison 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 |
comparison
equal
deleted
inserted
replaced
17:129ea1e6d783 | 18:af1871eacc83 |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\Core\ParamConverter; | 3 namespace Drupal\Core\ParamConverter; |
4 | 4 |
5 use Drupal\Core\Entity\EntityInterface; | |
5 use Drupal\Core\Entity\EntityRepositoryInterface; | 6 use Drupal\Core\Entity\EntityRepositoryInterface; |
6 use Drupal\Core\Entity\EntityTypeManagerInterface; | 7 use Drupal\Core\Entity\EntityTypeManagerInterface; |
8 use Drupal\Core\Entity\TranslatableInterface; | |
7 use Symfony\Component\Routing\Route; | 9 use Symfony\Component\Routing\Route; |
8 | 10 |
9 /** | 11 /** |
10 * Parameter converter for upcasting entity revision IDs to full objects. | 12 * Parameter converter for upcasting entity revision IDs to full objects. |
11 * | 13 * |
22 * entity_example_revision: | 24 * entity_example_revision: |
23 * type: entity_revision:entity_example | 25 * type: entity_revision:entity_example |
24 * @endcode | 26 * @endcode |
25 */ | 27 */ |
26 class EntityRevisionParamConverter implements ParamConverterInterface { | 28 class EntityRevisionParamConverter implements ParamConverterInterface { |
29 | |
30 use DynamicEntityTypeParamConverterTrait; | |
27 | 31 |
28 /** | 32 /** |
29 * The entity type manager. | 33 * The entity type manager. |
30 * | 34 * |
31 * @var \Drupal\Core\Entity\EntityTypeManagerInterface | 35 * @var \Drupal\Core\Entity\EntityTypeManagerInterface |
54 | 58 |
55 /** | 59 /** |
56 * {@inheritdoc} | 60 * {@inheritdoc} |
57 */ | 61 */ |
58 public function convert($value, $definition, $name, array $defaults) { | 62 public function convert($value, $definition, $name, array $defaults) { |
59 list (, $entity_type_id) = explode(':', $definition['type'], 2); | 63 $entity_type_id = $this->getEntityTypeFromDefaults($definition, $name, $defaults); |
60 $entity = $this->entityTypeManager->getStorage($entity_type_id)->loadRevision($value); | 64 $entity = $this->entityTypeManager->getStorage($entity_type_id)->loadRevision($value); |
61 return $this->entityRepository->getTranslationFromContext($entity); | 65 |
66 // If the entity type is translatable, ensure we return the proper | |
67 // translation object for the current context. | |
68 if ($entity instanceof EntityInterface && $entity instanceof TranslatableInterface) { | |
69 $entity = $this->entityRepository->getTranslationFromContext($entity, NULL, ['operation' => 'entity_upcast']); | |
70 } | |
71 | |
72 return $entity; | |
62 } | 73 } |
63 | 74 |
64 /** | 75 /** |
65 * {@inheritdoc} | 76 * {@inheritdoc} |
66 */ | 77 */ |