drupal-graphql / drupal-graphql/graphql

[4.x] entity_reference parent's language

Open
#1,149 3 comments 0 reactions 0 assignees View on GitHub
4.x question
Dominant language
PHP
Stars
287
Forks
198
PR merge metrics
No merged PRs in 30d

Description

nested Entity loaded via entity reference field come in the default language, not in the current language, meaning the language of the parent.
I can't find a way to get the right language from entity_reference.

```gql
type Article implements NodeInterface {
...
linked_materials: [Materiau]
...
}
type Materiau implements NodeInterface {
id: Int!
uuid: String!
title: String!
...
}
```

```php
$registry->addFieldResolver('Article', 'linked_materials',
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_linked_materials'))
);
```

where i am now with my try
``` php
$registry->addFieldResolver('Article', 'linked_materials',
$builder->compose(
$builder->callback(function($parent, $args){
$linkedmaterials = $parent->get('field_linked_materials')->getValue();
$nids = [];
foreach ($linkedmaterials as $key => $value) {
$nids[] = $value['target_id'];
}
$lang = $parent->language()->getId();
// return [
// "ids" => $nids,
// "language" => $lang
// ];
return $nids;
}),
$builder->produce('entity_load_multiple')
->map('type', $builder->fromValue('node'))
->map('bundles', $builder->fromValue(['materiau']))
->map('ids', $builder->fromParent())
->map('language', $builder->fromValue('fr')) // hard coded language working, how can i transmit the language from the parent ?
)
);
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.