Skip to content
Snippets Groups Projects

Issue #3199697: Add JSON:API Translation experimental module

Compare and
20 files
+ 1905
12
Compare changes
  • Side-by-side
  • Inline
Files
20
@@ -122,7 +122,7 @@ public function setLatestRevisionCheck(LatestRevisionCheck $latest_revision_chec
public function getAccessCheckedResourceObject(EntityInterface $entity, ?AccountInterface $account = NULL) {
$account = $account ?: $this->currentUser;
$resource_type = $this->resourceTypeRepository->get($entity->getEntityTypeId(), $entity->bundle());
$entity = $this->entityRepository->getTranslationFromContext($entity, NULL, ['operation' => 'entity_upcast']);
$entity = $this->getEntityTranslation($entity);
$access = $this->checkEntityAccess($entity, 'view', $account);
$entity->addCacheableDependency($access);
if (!$access->isAllowed()) {
@@ -141,6 +141,19 @@ public function getAccessCheckedResourceObject(EntityInterface $entity, ?Account
return ResourceObject::createFromEntity($resource_type, $entity);
}
/**
* Returns the appropriate translation to operate on.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* An entity object.
*
* @return \Drupal\Core\Entity\EntityInterface
* An entity translation object.
*/
protected function getEntityTranslation(EntityInterface $entity): EntityInterface {
return $this->entityRepository->getTranslationFromContext($entity, NULL, ['operation' => 'entity_upcast']);
}
/**
* Checks access to the given entity.
*
Loading