Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity DataProducers throw error for missing translations #1307

Open
wants to merge 1 commit into
base: 8.x-4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ public function resolve($type, $id, ?string $language, ?array $bundles, ?bool $a

// Get the correct translation.
if (isset($language) && $language !== $entity->language()->getId() && $entity instanceof TranslatableInterface) {
$entity = $entity->getTranslation($language);
$entity->addCacheContexts(["static:language:{$language}"]);
if ($entity->hasTranslation($language)) {
$entity = $entity->getTranslation($language);
$entity->addCacheContexts(["static:language:{$language}"]);
}
}

// Check if the passed user (or current user if none is passed) has access
Expand Down
6 changes: 4 additions & 2 deletions src/Plugin/GraphQL/DataProducer/Entity/EntityLoadByUuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ public function resolve($type, $uuid, ?string $language, ?array $bundles, ?bool

// Get the correct translation.
if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface) {
$entity = $entity->getTranslation($language);
$entity->addCacheContexts(["static:language:{$language}"]);
if ($entity->hasTranslation($language)) {
$entity = $entity->getTranslation($language);
$entity->addCacheContexts(["static:language:{$language}"]);
}
}

// Check if the passed user (or current user if none is passed) has access
Expand Down
6 changes: 4 additions & 2 deletions src/Plugin/GraphQL/DataProducer/Entity/EntityLoadMultiple.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ public function resolve($type, array $ids, ?string $language, ?array $bundles, b
}

if (isset($language) && $language !== $entities[$id]->language()->getId() && $entities[$id] instanceof TranslatableInterface) {
$entities[$id] = $entities[$id]->getTranslation($language);
$entities[$id]->addCacheContexts(["static:language:{$language}"]);
if ($entities[$id]->hasTranslation($language)) {
$entities[$id] = $entities[$id]->getTranslation($language);
$entities[$id]->addCacheContexts(["static:language:{$language}"]);
}
}

if ($access) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function __construct(array $configuration, $pluginId, $pluginDefinition,
* @return \Drupal\Core\Entity\EntityInterface|null
*/
public function resolve(EntityInterface $entity, $language, ?bool $access, ?AccountInterface $accessUser, ?string $accessOperation, FieldContext $context) {
if ($entity instanceof TranslatableInterface && $entity->isTranslatable()) {
if ($entity instanceof TranslatableInterface && $entity->isTranslatable() && $entity->hasTranslation($language)) {
$entity = $entity->getTranslation($language);
$entity->addCacheContexts(["static:language:{$language}"]);
// Check if the passed user (or current user if none is passed) has access
Expand Down
6 changes: 4 additions & 2 deletions src/Plugin/GraphQL/DataProducer/Routing/RouteEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ public function resolve($url, ?string $language, FieldContext $context): ?Deferr

// Get the correct translation.
if (isset($language) && $language != $entity->language()->getId() && $entity instanceof TranslatableInterface) {
$entity = $entity->getTranslation($language);
$entity->addCacheContexts(["static:language:{$language}"]);
if ($entity->hasTranslation($language)) {
$entity = $entity->getTranslation($language);
$entity->addCacheContexts(["static:language:{$language}"]);
}
}

$access = $entity->access('view', NULL, TRUE);
Expand Down
6 changes: 4 additions & 2 deletions src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ public function resolve(string $vid, int $parent, ?int $max_depth, ?string $lang
$context->addCacheableDependency($entities[$id]);

if (isset($language) && $language !== $entities[$id]->language()->getId() && $entities[$id] instanceof TranslatableInterface) {
$entities[$id] = $entities[$id]->getTranslation($language);
$entities[$id]->addCacheContexts(["static:language:{$language}"]);
if ($entities[$id]->hasTranslation($language)) {
$entities[$id] = $entities[$id]->getTranslation($language);
$entities[$id]->addCacheContexts(["static:language:{$language}"]);
}
}

if ($access) {
Expand Down