Skip to content

Commit 9c3d84f

Browse files
committed
invalid translation language
bugfix removed patch
1 parent a05b635 commit 9c3d84f

File tree

6 files changed

+21
-11
lines changed

6 files changed

+21
-11
lines changed

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)