Skip to content

Commit 4b7e7b0

Browse files
committed
invalid translation language
bugfix
1 parent a05b635 commit 4b7e7b0

File tree

7 files changed

+119
-11
lines changed

7 files changed

+119
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
7+
// Get the correct translation.
8+
if (isset($language) && $language !== $entity->language()->getId() && $entity instanceof TranslatableInterface) {
9+
- $entity = $entity->getTranslation($language);
10+
- $entity->addCacheContexts(["static:language:{$language}"]);
11+
+ if ($entity->hasTranslation($language)) {
12+
+ $entity = $entity->getTranslation($language);
13+
+ $entity->addCacheContexts(["static:language:{$language}"]);
14+
+ }
15+
}
16+
17+
// Check if the passed user (or current user if none is passed) has access
18+
diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php
19+
index 10e2d40..e4e6ed0 100644
20+
--- a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php
21+
+++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php
22+
@@ -165,8 +165,10 @@ class EntityLoadByUuid extends DataProducerPluginBase implements ContainerFactor
23+
24+
// Get the correct translation.
25+
if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface) {
26+
- $entity = $entity->getTranslation($language);
27+
- $entity->addCacheContexts(["static:language:{$language}"]);
28+
+ if ($entity->hasTranslation($language)) {
29+
+ $entity = $entity->getTranslation($language);
30+
+ $entity->addCacheContexts(["static:language:{$language}"]);
31+
+ }
32+
}
33+
34+
// Check if the passed user (or current user if none is passed) has access
35+
diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php
36+
index 2a0259c..27a19e5 100644
37+
--- a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php
38+
+++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php
39+
@@ -172,8 +172,10 @@ class EntityLoadMultiple extends DataProducerPluginBase implements ContainerFact
40+
}
41+
42+
if (isset($language) && $language !== $entities[$id]->language()->getId() && $entities[$id] instanceof TranslatableInterface) {
43+
- $entities[$id] = $entities[$id]->getTranslation($language);
44+
- $entities[$id]->addCacheContexts(["static:language:{$language}"]);
45+
+ if ($entities[$id]->hasTranslation($language)) {
46+
+ $entities[$id] = $entities[$id]->getTranslation($language);
47+
+ $entities[$id]->addCacheContexts(["static:language:{$language}"]);
48+
+ }
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 633bdc2..3773a9b 100644
54+
--- a/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php
55+
+++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php
56+
@@ -101,7 +101,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) {
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 10ea4e6..1eef22a 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+
71+
// Get the correct translation.
72+
if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface) {
73+
- $entity = $entity->getTranslation($language);
74+
- $entity->addCacheContexts(["static:language:{$language}"]);
75+
+ if ($entity->hasTranslation($language)) {
76+
+ $entity = $entity->getTranslation($language);
77+
+ $entity->addCacheContexts(["static:language:{$language}"]);
78+
+ }
79+
}
80+
81+
$access = $entity->access('view', NULL, TRUE);
82+
diff --git a/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php b/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php
83+
index 1bcd624..8b2caf2 100644
84+
--- a/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php
85+
+++ b/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php
86+
@@ -175,8 +175,10 @@ class TaxonomyLoadTree extends DataProducerPluginBase implements ContainerFactor
87+
$context->addCacheableDependency($entities[$id]);
88+
89+
if (isset($language) && $language !== $entities[$id]->language()->getId() && $entities[$id] instanceof TranslatableInterface) {
90+
- $entities[$id] = $entities[$id]->getTranslation($language);
91+
- $entities[$id]->addCacheContexts(["static:language:{$language}"]);
92+
+ if ($entities[$id]->hasTranslation($language)) {
93+
+ $entities[$id] = $entities[$id]->getTranslation($language);
94+
+ $entities[$id]->addCacheContexts(["static:language:{$language}"]);
95+
+ }
96+
}
97+
98+
if ($access) {

src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,10 @@ public function resolve($type, $id, ?string $language, ?array $bundles, ?bool $a
172172

173173
// Get the correct translation.
174174
if (isset($language) && $language !== $entity->language()->getId() && $entity instanceof TranslatableInterface) {
175-
$entity = $entity->getTranslation($language);
176-
$entity->addCacheContexts(["static:language:{$language}"]);
175+
if ($entity->hasTranslation($language)) {
176+
$entity = $entity->getTranslation($language);
177+
$entity->addCacheContexts(["static:language:{$language}"]);
178+
}
177179
}
178180

179181
// Check if the passed user (or current user if none is passed) has access

src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,10 @@ public function resolve($type, $uuid, ?string $language, ?array $bundles, ?bool
165165

166166
// Get the correct translation.
167167
if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface) {
168-
$entity = $entity->getTranslation($language);
169-
$entity->addCacheContexts(["static:language:{$language}"]);
168+
if ($entity->hasTranslation($language)) {
169+
$entity = $entity->getTranslation($language);
170+
$entity->addCacheContexts(["static:language:{$language}"]);
171+
}
170172
}
171173

172174
// Check if the passed user (or current user if none is passed) has access

src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,10 @@ public function resolve($type, array $ids, ?string $language, ?array $bundles, b
172172
}
173173

174174
if (isset($language) && $language !== $entities[$id]->language()->getId() && $entities[$id] instanceof TranslatableInterface) {
175-
$entities[$id] = $entities[$id]->getTranslation($language);
176-
$entities[$id]->addCacheContexts(["static:language:{$language}"]);
175+
if ($entities[$id]->hasTranslation($language)) {
176+
$entities[$id] = $entities[$id]->getTranslation($language);
177+
$entities[$id]->addCacheContexts(["static:language:{$language}"]);
178+
}
177179
}
178180

179181
if ($access) {

src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function __construct(array $configuration, $pluginId, $pluginDefinition,
103103
* @return \Drupal\Core\Entity\EntityInterface|null
104104
*/
105105
public function resolve(EntityInterface $entity, $language, ?bool $access, ?AccountInterface $accessUser, ?string $accessOperation, FieldContext $context) {
106-
if ($entity instanceof TranslatableInterface && $entity->isTranslatable()) {
106+
if ($entity instanceof TranslatableInterface && $entity->isTranslatable() && $entity->hasTranslation($language)) {
107107
$entity = $entity->getTranslation($language);
108108
$entity->addCacheContexts(["static:language:{$language}"]);
109109
// Check if the passed user (or current user if none is passed) has access

src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,10 @@ public function resolve($url, ?string $language, FieldContext $context): ?Deferr
126126

127127
// Get the correct translation.
128128
if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface) {
129-
$entity = $entity->getTranslation($language);
130-
$entity->addCacheContexts(["static:language:{$language}"]);
129+
if ($entity->hasTranslation($language)) {
130+
$entity = $entity->getTranslation($language);
131+
$entity->addCacheContexts(["static:language:{$language}"]);
132+
}
131133
}
132134

133135
$access = $entity->access('view', NULL, TRUE);

src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,10 @@ public function resolve(string $vid, int $parent, ?int $max_depth, ?string $lang
175175
$context->addCacheableDependency($entities[$id]);
176176

177177
if (isset($language) && $language !== $entities[$id]->language()->getId() && $entities[$id] instanceof TranslatableInterface) {
178-
$entities[$id] = $entities[$id]->getTranslation($language);
179-
$entities[$id]->addCacheContexts(["static:language:{$language}"]);
178+
if ($entities[$id]->hasTranslation($language)) {
179+
$entities[$id] = $entities[$id]->getTranslation($language);
180+
$entities[$id]->addCacheContexts(["static:language:{$language}"]);
181+
}
180182
}
181183

182184
if ($access) {

0 commit comments

Comments
 (0)