materio-d9/patches/graphql-fix-invalid-transla...

109 lines
5.9 KiB
Diff
Raw Permalink Normal View History

commit 9c3d84fbb3e0e2a4ad99ef593b975cde7bc2547f
Author: bach <bachir@figureslibres.io>
Date: Mon Sep 19 15:41:32 2022 +0200
invalid translation language
bugfix
removed patch
2022-09-19 15:58:11 +02:00
diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php
index 408af0af..b6f9d8d8 100644
2022-09-19 15:58:11 +02:00
--- a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php
+++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php
@@ -172,8 +172,10 @@ class EntityLoad extends DataProducerPluginBase implements ContainerFactoryPlugi
// Get the correct translation.
if (isset($language) && $language !== $entity->language()->getId() && $entity instanceof TranslatableInterface) {
- $entity = $entity->getTranslation($language);
- $entity->addCacheContexts(["static:language:{$language}"]);
+ if ($entity->hasTranslation($language)) {
+ $entity = $entity->getTranslation($language);
+ $entity->addCacheContexts(["static:language:{$language}"]);
+ }
}
// Check if the passed user (or current user if none is passed) has access
diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php
index a400da19..4fb1d8d7 100644
2022-09-19 15:58:11 +02:00
--- a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php
+++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php
@@ -165,8 +165,10 @@ class EntityLoadByUuid extends DataProducerPluginBase implements ContainerFactor
// Get the correct translation.
if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface) {
- $entity = $entity->getTranslation($language);
- $entity->addCacheContexts(["static:language:{$language}"]);
+ if ($entity->hasTranslation($language)) {
+ $entity = $entity->getTranslation($language);
+ $entity->addCacheContexts(["static:language:{$language}"]);
+ }
}
// Check if the passed user (or current user if none is passed) has access
diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php
index 2b456aad..92f2c898 100644
2022-09-19 15:58:11 +02:00
--- a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php
+++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php
@@ -172,8 +172,10 @@ class EntityLoadMultiple extends DataProducerPluginBase implements ContainerFact
}
if (isset($language) && $language !== $entities[$id]->language()->getId() && $entities[$id] instanceof TranslatableInterface) {
- $entities[$id] = $entities[$id]->getTranslation($language);
- $entities[$id]->addCacheContexts(["static:language:{$language}"]);
+ if ($entities[$id]->hasTranslation($language)) {
+ $entities[$id] = $entities[$id]->getTranslation($language);
+ $entities[$id]->addCacheContexts(["static:language:{$language}"]);
+ }
}
if ($access) {
diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php
index 1a30c65d..5d3f1268 100644
2022-09-19 15:58:11 +02:00
--- a/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php
+++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php
@@ -103,7 +103,7 @@ class EntityTranslation extends DataProducerPluginBase implements ContainerFacto
2022-09-19 15:58:11 +02:00
* @return \Drupal\Core\Entity\EntityInterface|null
*/
public function resolve(EntityInterface $entity, $language, ?bool $access, ?AccountInterface $accessUser, ?string $accessOperation, FieldContext $context) {
2022-09-19 15:58:11 +02:00
- if ($entity instanceof TranslatableInterface && $entity->isTranslatable()) {
+ if ($entity instanceof TranslatableInterface && $entity->isTranslatable() && $entity->hasTranslation($language)) {
$entity = $entity->getTranslation($language);
$entity->addCacheContexts(["static:language:{$language}"]);
// Check if the passed user (or current user if none is passed) has access
diff --git a/src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php b/src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php
index e08c7bdd..46c64bbb 100644
2022-09-19 15:58:11 +02:00
--- a/src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php
+++ b/src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php
@@ -126,8 +126,10 @@ class RouteEntity extends DataProducerPluginBase implements ContainerFactoryPlug
// Get the correct translation.
if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface) {
- $entity = $entity->getTranslation($language);
- $entity->addCacheContexts(["static:language:{$language}"]);
+ if ($entity->hasTranslation($language)) {
+ $entity = $entity->getTranslation($language);
+ $entity->addCacheContexts(["static:language:{$language}"]);
+ }
}
$access = $entity->access('view', NULL, TRUE);
diff --git a/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php b/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php
index 3f2229fd..b0753acf 100644
2022-09-19 15:58:11 +02:00
--- a/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php
+++ b/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php
@@ -175,8 +175,10 @@ class TaxonomyLoadTree extends DataProducerPluginBase implements ContainerFactor
$context->addCacheableDependency($entities[$id]);
if (isset($language) && $language !== $entities[$id]->language()->getId() && $entities[$id] instanceof TranslatableInterface) {
- $entities[$id] = $entities[$id]->getTranslation($language);
- $entities[$id]->addCacheContexts(["static:language:{$language}"]);
+ if ($entities[$id]->hasTranslation($language)) {
+ $entities[$id] = $entities[$id]->getTranslation($language);
+ $entities[$id]->addCacheContexts(["static:language:{$language}"]);
+ }
}
if ($access) {