Skip to content

Commit

Permalink
invalid translation language
Browse files Browse the repository at this point in the history
bugfix

removed patch
  • Loading branch information
bachy committed Aug 15, 2024
1 parent a05b635 commit 9c3d84f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
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

0 comments on commit 9c3d84f

Please sign in to comment.