graphql-fix-invalid-translation-language.patch 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. commit fc8cbeca3774ea4dce6c8768b1051144de5f1681
  2. Author: bach <bachir@figureslibres.io>
  3. Date: Wed Mar 3 17:34:33 2021 +0100
  4. fixe Invalid translation language
  5. diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php
  6. index f83be91..124cd53 100644
  7. --- a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php
  8. +++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php
  9. @@ -165,9 +165,11 @@ class EntityLoad extends DataProducerPluginBase implements ContainerFactoryPlugi
  10. }
  11. // Get the correct translation.
  12. - if (isset($language) && $language !== $entity->language()->getId() && $entity instanceof TranslatableInterface) {
  13. - $entity = $entity->getTranslation($language);
  14. - $entity->addCacheContexts(["static:language:{$language}"]);
  15. + if (isset($language) && $language !== $entity->language()->getId() && $entity instanceof TranslatableInterface && $entity->isTranslatable()) {
  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 10e2d40..e98b514 100644
  24. --- a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php
  25. +++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php
  26. @@ -164,9 +164,11 @@ class EntityLoadByUuid extends DataProducerPluginBase implements ContainerFactor
  27. }
  28. // Get the correct translation.
  29. - if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface) {
  30. - $entity = $entity->getTranslation($language);
  31. - $entity->addCacheContexts(["static:language:{$language}"]);
  32. + if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface && $entity->isTranslatable()) {
  33. + if($entity->hasTranslation($language)){
  34. + $entity = $entity->getTranslation($language);
  35. + $entity->addCacheContexts(["static:language:{$language}"]);
  36. + }
  37. }
  38. // Check if the passed user (or current user if none is passed) has access
  39. diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php
  40. index 4653aa0..526929b 100644
  41. --- a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php
  42. +++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php
  43. @@ -168,9 +168,11 @@ class EntityLoadMultiple extends DataProducerPluginBase implements ContainerFact
  44. continue;
  45. }
  46. - if (isset($language) && $language !== $entities[$id]->language()->getId() && $entities[$id] instanceof TranslatableInterface) {
  47. - $entities[$id] = $entities[$id]->getTranslation($language);
  48. - $entities[$id]->addCacheContexts(["static:language:{$language}"]);
  49. + if (isset($language) && $language !== $entities[$id]->language()->getId() && $entities[$id] instanceof TranslatableInterface && $entities[$id]->isTranslatable()) {
  50. + if($entities[$id]->hasTranslation($language)){
  51. + $entities[$id] = $entities[$id]->getTranslation($language);
  52. + $entities[$id]->addCacheContexts(["static:language:{$language}"]);
  53. + }
  54. }
  55. if ($access) {
  56. diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php
  57. index 633bdc2..3773a9b 100644
  58. --- a/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php
  59. +++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php
  60. @@ -101,7 +101,7 @@ class EntityTranslation extends DataProducerPluginBase implements ContainerFacto
  61. * @return \Drupal\Core\Entity\EntityInterface|null
  62. */
  63. public function resolve(EntityInterface $entity, $language, ?bool $access, ?AccountInterface $accessUser, ?string $accessOperation) {
  64. - if ($entity instanceof TranslatableInterface && $entity->isTranslatable()) {
  65. + if ($entity instanceof TranslatableInterface && $entity->isTranslatable() && $entity->hasTranslation($language)) {
  66. $entity = $entity->getTranslation($language);
  67. $entity->addCacheContexts(["static:language:{$language}"]);
  68. // Check if the passed user (or current user if none is passed) has access
  69. diff --git a/src/Plugin/GraphQL/DataProducer/Field/EntityReference.php b/src/Plugin/GraphQL/DataProducer/Field/EntityReference.php
  70. index 2d0a974..1346cd9 100644
  71. --- a/src/Plugin/GraphQL/DataProducer/Field/EntityReference.php
  72. +++ b/src/Plugin/GraphQL/DataProducer/Field/EntityReference.php
  73. @@ -168,9 +168,11 @@ class EntityReference extends DataProducerPluginBase implements ContainerFactory
  74. }
  75. // Get the correct translation.
  76. - if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface) {
  77. - $entity = $entity->getTranslation($language);
  78. - $entity->addCacheContexts(["static:language:{$language}"]);
  79. + if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface && $entity->isTranslatable()) {
  80. + if($entity->hasTranslation($language)){
  81. + $entity = $entity->getTranslation($language);
  82. + $entity->addCacheContexts(["static:language:{$language}"]);
  83. + }
  84. }
  85. // Check if the passed user (or current user if none is passed) has
  86. diff --git a/src/Plugin/GraphQL/DataProducer/Field/EntityReferenceLayoutRevisions.php b/src/Plugin/GraphQL/DataProducer/Field/EntityReferenceLayoutRevisions.php
  87. index ddcc2ab..8650a52 100644
  88. --- a/src/Plugin/GraphQL/DataProducer/Field/EntityReferenceLayoutRevisions.php
  89. +++ b/src/Plugin/GraphQL/DataProducer/Field/EntityReferenceLayoutRevisions.php
  90. @@ -174,9 +174,11 @@ class EntityReferenceLayoutRevisions extends DataProducerPluginBase implements C
  91. }
  92. // Get the correct translation.
  93. - if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface) {
  94. - $entity = $entity->getTranslation($language);
  95. - $entity->addCacheContexts(["static:language:{$language}"]);
  96. + if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface && $entity->isTranslatable()) {
  97. + if($entity->hasTranslation($language)){
  98. + $entity = $entity->getTranslation($language);
  99. + $entity->addCacheContexts(["static:language:{$language}"]);
  100. + }
  101. }
  102. // Check if the passed user (or current user if none is passed) has
  103. diff --git a/src/Plugin/GraphQL/DataProducer/Field/EntityReferenceRevisions.php b/src/Plugin/GraphQL/DataProducer/Field/EntityReferenceRevisions.php
  104. index 31a1d15..8c950e8 100644
  105. --- a/src/Plugin/GraphQL/DataProducer/Field/EntityReferenceRevisions.php
  106. +++ b/src/Plugin/GraphQL/DataProducer/Field/EntityReferenceRevisions.php
  107. @@ -174,9 +174,11 @@ class EntityReferenceRevisions extends DataProducerPluginBase implements Contain
  108. }
  109. // Get the correct translation.
  110. - if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface) {
  111. - $entity = $entity->getTranslation($language);
  112. - $entity->addCacheContexts(["static:language:{$language}"]);
  113. + if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface && $entity->isTranslatable()) {
  114. + if($entity->hasTranslation($language)){
  115. + $entity = $entity->getTranslation($language);
  116. + $entity->addCacheContexts(["static:language:{$language}"]);
  117. + }
  118. }
  119. // Check if the passed user (or current user if none is passed) has
  120. diff --git a/src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php b/src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php
  121. index a0c9be6..48678bc 100644
  122. --- a/src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php
  123. +++ b/src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php
  124. @@ -125,9 +125,11 @@ class RouteEntity extends DataProducerPluginBase implements ContainerFactoryPlug
  125. }
  126. // Get the correct translation.
  127. - if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface) {
  128. - $entity = $entity->getTranslation($language);
  129. - $entity->addCacheContexts(["static:language:{$language}"]);
  130. + if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface && $entity->isTranslatable()) {
  131. + if($entity->hasTranslation($language)){
  132. + $entity = $entity->getTranslation($language);
  133. + $entity->addCacheContexts(["static:language:{$language}"]);
  134. + }
  135. }
  136. $access = $entity->access('view', NULL, TRUE);
  137. diff --git a/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php b/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php
  138. index 1bcd624..a23a256 100644
  139. --- a/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php
  140. +++ b/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php
  141. @@ -174,9 +174,11 @@ class TaxonomyLoadTree extends DataProducerPluginBase implements ContainerFactor
  142. foreach ($entities as $id => $entity) {
  143. $context->addCacheableDependency($entities[$id]);
  144. - if (isset($language) && $language !== $entities[$id]->language()->getId() && $entities[$id] instanceof TranslatableInterface) {
  145. - $entities[$id] = $entities[$id]->getTranslation($language);
  146. - $entities[$id]->addCacheContexts(["static:language:{$language}"]);
  147. + if (isset($language) && $language !== $entities[$id]->language()->getId() && $entities[$id] instanceof TranslatableInterface && $entities[$id]->isTranslatable()) {
  148. + if($entities[$id]->hasTranslation($language)){
  149. + $entities[$id] = $entities[$id]->getTranslation($language);
  150. + $entities[$id]->addCacheContexts(["static:language:{$language}"]);
  151. + }
  152. }
  153. if ($access) {