graphql-fix-invalid-translation-language-dev.patch 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. commit 9c3d84fbb3e0e2a4ad99ef593b975cde7bc2547f
  2. Author: bach <bachir@figureslibres.io>
  3. Date: Mon Sep 19 15:41:32 2022 +0200
  4. invalid translation language
  5. bugfix
  6. removed patch
  7. diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php
  8. index 408af0af..b6f9d8d8 100644
  9. --- a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php
  10. +++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php
  11. @@ -172,8 +172,10 @@ class EntityLoad extends DataProducerPluginBase implements ContainerFactoryPlugi
  12. // Get the correct translation.
  13. if (isset($language) && $language !== $entity->language()->getId() && $entity instanceof TranslatableInterface) {
  14. - $entity = $entity->getTranslation($language);
  15. - $entity->addCacheContexts(["static:language:{$language}"]);
  16. + if ($entity->hasTranslation($language)) {
  17. + $entity = $entity->getTranslation($language);
  18. + $entity->addCacheContexts(["static:language:{$language}"]);
  19. + }
  20. }
  21. // Check if the passed user (or current user if none is passed) has access
  22. diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php
  23. index a400da19..4fb1d8d7 100644
  24. --- a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php
  25. +++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php
  26. @@ -165,8 +165,10 @@ class EntityLoadByUuid extends DataProducerPluginBase implements ContainerFactor
  27. // Get the correct translation.
  28. if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface) {
  29. - $entity = $entity->getTranslation($language);
  30. - $entity->addCacheContexts(["static:language:{$language}"]);
  31. + if ($entity->hasTranslation($language)) {
  32. + $entity = $entity->getTranslation($language);
  33. + $entity->addCacheContexts(["static:language:{$language}"]);
  34. + }
  35. }
  36. // Check if the passed user (or current user if none is passed) has access
  37. diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php
  38. index 2b456aad..92f2c898 100644
  39. --- a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php
  40. +++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php
  41. @@ -172,8 +172,10 @@ class EntityLoadMultiple extends DataProducerPluginBase implements ContainerFact
  42. }
  43. if (isset($language) && $language !== $entities[$id]->language()->getId() && $entities[$id] instanceof TranslatableInterface) {
  44. - $entities[$id] = $entities[$id]->getTranslation($language);
  45. - $entities[$id]->addCacheContexts(["static:language:{$language}"]);
  46. + if ($entities[$id]->hasTranslation($language)) {
  47. + $entities[$id] = $entities[$id]->getTranslation($language);
  48. + $entities[$id]->addCacheContexts(["static:language:{$language}"]);
  49. + }
  50. }
  51. if ($access) {
  52. diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php
  53. index 1a30c65d..5d3f1268 100644
  54. --- a/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php
  55. +++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php
  56. @@ -103,7 +103,7 @@ class EntityTranslation extends DataProducerPluginBase implements ContainerFacto
  57. * @return \Drupal\Core\Entity\EntityInterface|null
  58. */
  59. public function resolve(EntityInterface $entity, $language, ?bool $access, ?AccountInterface $accessUser, ?string $accessOperation, FieldContext $context) {
  60. - if ($entity instanceof TranslatableInterface && $entity->isTranslatable()) {
  61. + if ($entity instanceof TranslatableInterface && $entity->isTranslatable() && $entity->hasTranslation($language)) {
  62. $entity = $entity->getTranslation($language);
  63. $entity->addCacheContexts(["static:language:{$language}"]);
  64. // Check if the passed user (or current user if none is passed) has access
  65. diff --git a/src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php b/src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php
  66. index e08c7bdd..46c64bbb 100644
  67. --- a/src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php
  68. +++ b/src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php
  69. @@ -126,8 +126,10 @@ class RouteEntity extends DataProducerPluginBase implements ContainerFactoryPlug
  70. // Get the correct translation.
  71. if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface) {
  72. - $entity = $entity->getTranslation($language);
  73. - $entity->addCacheContexts(["static:language:{$language}"]);
  74. + if ($entity->hasTranslation($language)) {
  75. + $entity = $entity->getTranslation($language);
  76. + $entity->addCacheContexts(["static:language:{$language}"]);
  77. + }
  78. }
  79. $access = $entity->access('view', NULL, TRUE);
  80. diff --git a/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php b/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php
  81. index 3f2229fd..b0753acf 100644
  82. --- a/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php
  83. +++ b/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php
  84. @@ -175,8 +175,10 @@ class TaxonomyLoadTree extends DataProducerPluginBase implements ContainerFactor
  85. $context->addCacheableDependency($entities[$id]);
  86. if (isset($language) && $language !== $entities[$id]->language()->getId() && $entities[$id] instanceof TranslatableInterface) {
  87. - $entities[$id] = $entities[$id]->getTranslation($language);
  88. - $entities[$id]->addCacheContexts(["static:language:{$language}"]);
  89. + if ($entities[$id]->hasTranslation($language)) {
  90. + $entities[$id] = $entities[$id]->getTranslation($language);
  91. + $entities[$id]->addCacheContexts(["static:language:{$language}"]);
  92. + }
  93. }
  94. if ($access) {