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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php
  2. index 867a28c..386b2b3 100644
  3. --- a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php
  4. +++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php
  5. @@ -172,8 +172,10 @@ class EntityLoad extends DataProducerPluginBase implements ContainerFactoryPlugi
  6. // Get the correct translation.
  7. if (isset($language) && $language !== $entity->language()->getId() && $entity instanceof TranslatableInterface) {
  8. - $entity = $entity->getTranslation($language);
  9. - $entity->addCacheContexts(["static:language:{$language}"]);
  10. + if ($entity->hasTranslation($language)) {
  11. + $entity = $entity->getTranslation($language);
  12. + $entity->addCacheContexts(["static:language:{$language}"]);
  13. + }
  14. }
  15. // Check if the passed user (or current user if none is passed) has access
  16. diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php
  17. index 10e2d40..e4e6ed0 100644
  18. --- a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php
  19. +++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php
  20. @@ -165,8 +165,10 @@ class EntityLoadByUuid extends DataProducerPluginBase implements ContainerFactor
  21. // Get the correct translation.
  22. if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface) {
  23. - $entity = $entity->getTranslation($language);
  24. - $entity->addCacheContexts(["static:language:{$language}"]);
  25. + if ($entity->hasTranslation($language)) {
  26. + $entity = $entity->getTranslation($language);
  27. + $entity->addCacheContexts(["static:language:{$language}"]);
  28. + }
  29. }
  30. // Check if the passed user (or current user if none is passed) has access
  31. diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php
  32. index 2a0259c..27a19e5 100644
  33. --- a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php
  34. +++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php
  35. @@ -172,8 +172,10 @@ class EntityLoadMultiple extends DataProducerPluginBase implements ContainerFact
  36. }
  37. if (isset($language) && $language !== $entities[$id]->language()->getId() && $entities[$id] instanceof TranslatableInterface) {
  38. - $entities[$id] = $entities[$id]->getTranslation($language);
  39. - $entities[$id]->addCacheContexts(["static:language:{$language}"]);
  40. + if ($entities[$id]->hasTranslation($language)) {
  41. + $entities[$id] = $entities[$id]->getTranslation($language);
  42. + $entities[$id]->addCacheContexts(["static:language:{$language}"]);
  43. + }
  44. }
  45. if ($access) {
  46. diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php
  47. index 633bdc2..3773a9b 100644
  48. --- a/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php
  49. +++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php
  50. @@ -101,7 +101,7 @@ class EntityTranslation extends DataProducerPluginBase implements ContainerFacto
  51. * @return \Drupal\Core\Entity\EntityInterface|null
  52. */
  53. public function resolve(EntityInterface $entity, $language, ?bool $access, ?AccountInterface $accessUser, ?string $accessOperation) {
  54. - if ($entity instanceof TranslatableInterface && $entity->isTranslatable()) {
  55. + if ($entity instanceof TranslatableInterface && $entity->isTranslatable() && $entity->hasTranslation($language)) {
  56. $entity = $entity->getTranslation($language);
  57. $entity->addCacheContexts(["static:language:{$language}"]);
  58. // Check if the passed user (or current user if none is passed) has access
  59. diff --git a/src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php b/src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php
  60. index 10ea4e6..1eef22a 100644
  61. --- a/src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php
  62. +++ b/src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php
  63. @@ -126,8 +126,10 @@ class RouteEntity extends DataProducerPluginBase implements ContainerFactoryPlug
  64. // Get the correct translation.
  65. if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface) {
  66. - $entity = $entity->getTranslation($language);
  67. - $entity->addCacheContexts(["static:language:{$language}"]);
  68. + if ($entity->hasTranslation($language)) {
  69. + $entity = $entity->getTranslation($language);
  70. + $entity->addCacheContexts(["static:language:{$language}"]);
  71. + }
  72. }
  73. $access = $entity->access('view', NULL, TRUE);
  74. diff --git a/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php b/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php
  75. index 1bcd624..8b2caf2 100644
  76. --- a/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php
  77. +++ b/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php
  78. @@ -175,8 +175,10 @@ class TaxonomyLoadTree extends DataProducerPluginBase implements ContainerFactor
  79. $context->addCacheableDependency($entities[$id]);
  80. if (isset($language) && $language !== $entities[$id]->language()->getId() && $entities[$id] instanceof TranslatableInterface) {
  81. - $entities[$id] = $entities[$id]->getTranslation($language);
  82. - $entities[$id]->addCacheContexts(["static:language:{$language}"]);
  83. + if ($entities[$id]->hasTranslation($language)) {
  84. + $entities[$id] = $entities[$id]->getTranslation($language);
  85. + $entities[$id]->addCacheContexts(["static:language:{$language}"]);
  86. + }
  87. }
  88. if ($access) {