Skip to content

Commit 7a503c3

Browse files
authored
Adding field for listing all entity translations. (#506)
1 parent e0d73dd commit 7a503c3

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Drupal\graphql_core\Plugin\GraphQL\Fields\Entity;
4+
5+
use Drupal\Core\Entity\ContentEntityInterface;
6+
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase;
7+
use Youshido\GraphQL\Execution\ResolveInfo;
8+
9+
/**
10+
* @GraphQLField(
11+
* id = "entity_translations",
12+
* name = "entityTranslations",
13+
* secure = true,
14+
* type = "[Entity]",
15+
* parents = {"Entity"}
16+
* )
17+
*/
18+
class EntityTranslations extends FieldPluginBase {
19+
20+
/**
21+
* {@inheritdoc}
22+
*/
23+
public function resolveValues($value, array $args, ResolveInfo $info) {
24+
if ($value instanceof ContentEntityInterface) {
25+
$languages = $value->getTranslationLanguages();
26+
foreach ($languages as $language) {
27+
yield $value->getTranslation($language->getId());
28+
}
29+
}
30+
}
31+
32+
}

0 commit comments

Comments
 (0)