Skip to content

Commit 45a4911

Browse files
committed
drupal-graphql#1322: Fix fatal error when attempting to load an entity for a language the entity is not translated into.
This same pattern happens in three plugins, this fixes in all of them.
1 parent eb467d6 commit 45a4911

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ 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+
if (!$entity->hasTranslation($language)) {
176+
return NULL;
177+
}
175178
$entity = $entity->getTranslation($language);
176179
$entity->addCacheContexts(["static:language:{$language}"]);
177180
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ 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+
if (!$entity->hasTranslation($language)) {
169+
return NULL;
170+
}
168171
$entity = $entity->getTranslation($language);
169172
$entity->addCacheContexts(["static:language:{$language}"]);
170173
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ 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+
if (!$entity->hasTranslation($language)) {
130+
return NULL;
131+
}
129132
$entity = $entity->getTranslation($language);
130133
$entity->addCacheContexts(["static:language:{$language}"]);
131134
}

0 commit comments

Comments
 (0)