From b6c6851837aaf3509bcd9a8929373c08452bd6f8 Mon Sep 17 00:00:00 2001 From: bach Date: Wed, 3 Mar 2021 17:58:35 +0100 Subject: [PATCH] forgot the graphql patch file --- .gitignore | 1 + ...hql-fix-invalid-translation-language.patch | 171 ++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 patches/graphql-fix-invalid-translation-language.patch diff --git a/.gitignore b/.gitignore index 4670276..a600e41 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ node_modules/ *.patch +~/patches/*.patch /.csslintrc /.eslintrc.json /.ht.router.php diff --git a/patches/graphql-fix-invalid-translation-language.patch b/patches/graphql-fix-invalid-translation-language.patch new file mode 100644 index 0000000..c55dd84 --- /dev/null +++ b/patches/graphql-fix-invalid-translation-language.patch @@ -0,0 +1,171 @@ +commit fc8cbeca3774ea4dce6c8768b1051144de5f1681 +Author: bach +Date: Wed Mar 3 17:34:33 2021 +0100 + + fixe Invalid translation language + +diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php +index f83be91..124cd53 100644 +--- a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php ++++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php +@@ -165,9 +165,11 @@ 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 (isset($language) && $language !== $entity->language()->getId() && $entity instanceof TranslatableInterface && $entity->isTranslatable()) { ++ 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 10e2d40..e98b514 100644 +--- a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php ++++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php +@@ -164,9 +164,11 @@ 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 (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface && $entity->isTranslatable()) { ++ 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 4653aa0..526929b 100644 +--- a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php ++++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php +@@ -168,9 +168,11 @@ class EntityLoadMultiple extends DataProducerPluginBase implements ContainerFact + continue; + } + +- 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 (isset($language) && $language !== $entities[$id]->language()->getId() && $entities[$id] instanceof TranslatableInterface && $entities[$id]->isTranslatable()) { ++ 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 633bdc2..3773a9b 100644 +--- a/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php ++++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php +@@ -101,7 +101,7 @@ class EntityTranslation extends DataProducerPluginBase implements ContainerFacto + * @return \Drupal\Core\Entity\EntityInterface|null + */ + public function resolve(EntityInterface $entity, $language, ?bool $access, ?AccountInterface $accessUser, ?string $accessOperation) { +- 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/Field/EntityReference.php b/src/Plugin/GraphQL/DataProducer/Field/EntityReference.php +index 2d0a974..1346cd9 100644 +--- a/src/Plugin/GraphQL/DataProducer/Field/EntityReference.php ++++ b/src/Plugin/GraphQL/DataProducer/Field/EntityReference.php +@@ -168,9 +168,11 @@ class EntityReference extends DataProducerPluginBase implements ContainerFactory + } + + // Get the correct translation. +- if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface) { +- $entity = $entity->getTranslation($language); +- $entity->addCacheContexts(["static:language:{$language}"]); ++ if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface && $entity->isTranslatable()) { ++ 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 +diff --git a/src/Plugin/GraphQL/DataProducer/Field/EntityReferenceLayoutRevisions.php b/src/Plugin/GraphQL/DataProducer/Field/EntityReferenceLayoutRevisions.php +index ddcc2ab..8650a52 100644 +--- a/src/Plugin/GraphQL/DataProducer/Field/EntityReferenceLayoutRevisions.php ++++ b/src/Plugin/GraphQL/DataProducer/Field/EntityReferenceLayoutRevisions.php +@@ -174,9 +174,11 @@ class EntityReferenceLayoutRevisions extends DataProducerPluginBase implements C + } + + // Get the correct translation. +- if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface) { +- $entity = $entity->getTranslation($language); +- $entity->addCacheContexts(["static:language:{$language}"]); ++ if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface && $entity->isTranslatable()) { ++ 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 +diff --git a/src/Plugin/GraphQL/DataProducer/Field/EntityReferenceRevisions.php b/src/Plugin/GraphQL/DataProducer/Field/EntityReferenceRevisions.php +index 31a1d15..8c950e8 100644 +--- a/src/Plugin/GraphQL/DataProducer/Field/EntityReferenceRevisions.php ++++ b/src/Plugin/GraphQL/DataProducer/Field/EntityReferenceRevisions.php +@@ -174,9 +174,11 @@ class EntityReferenceRevisions extends DataProducerPluginBase implements Contain + } + + // Get the correct translation. +- if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface) { +- $entity = $entity->getTranslation($language); +- $entity->addCacheContexts(["static:language:{$language}"]); ++ if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface && $entity->isTranslatable()) { ++ 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 +diff --git a/src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php b/src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php +index a0c9be6..48678bc 100644 +--- a/src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php ++++ b/src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php +@@ -125,9 +125,11 @@ 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 (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface && $entity->isTranslatable()) { ++ 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 1bcd624..a23a256 100644 +--- a/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php ++++ b/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php +@@ -174,9 +174,11 @@ class TaxonomyLoadTree extends DataProducerPluginBase implements ContainerFactor + foreach ($entities as $id => $entity) { + $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 (isset($language) && $language !== $entities[$id]->language()->getId() && $entities[$id] instanceof TranslatableInterface && $entities[$id]->isTranslatable()) { ++ if($entities[$id]->hasTranslation($language)){ ++ $entities[$id] = $entities[$id]->getTranslation($language); ++ $entities[$id]->addCacheContexts(["static:language:{$language}"]); ++ } + } + + if ($access) {