fixed graphql linked_materials entity_reference translation

This commit is contained in:
Bachir Soussi Chiadmi 2021-01-19 11:42:14 +01:00
parent bc2bd2861c
commit 2cf2f378ce
12 changed files with 111 additions and 39 deletions

View File

@ -96,6 +96,7 @@ third_party_settings:
- field_workflow
- field_migration
- field_memo
- translation
parent_name: ''
weight: 1
format_type: tab
@ -240,12 +241,13 @@ content:
placeholder: ''
third_party_settings: { }
translation:
weight: 3
weight: 7
region: content
settings: { }
third_party_settings: { }
hidden:
created: true
flag: true
path: true
promote: true
status: true

View File

@ -14,7 +14,7 @@ bundle: article
label: Body
description: ''
required: false
translatable: false
translatable: true
default_value: { }
default_value_callback: ''
settings:

View File

@ -3,8 +3,12 @@ langcode: en
status: true
dependencies:
module:
- field_permissions
- node
- text
third_party_settings:
field_permissions:
permission_type: public
_core:
default_config_hash: EBUo7qOWqaiZaQ_RC9sLY5IoDKphS34v77VIHSACmVY
id: node.body

View File

@ -8,7 +8,7 @@ dependencies:
- content_translation
third_party_settings:
content_translation:
enabled: false
enabled: true
bundle_settings:
untranslatable_fields_hide: '0'
id: node.article

View File

@ -3,7 +3,7 @@ session:
url:
source: path_prefix
prefixes:
en: ''
en: en
fr: fr
domains:
en: ''

View File

@ -24,16 +24,15 @@ negotiation:
language_interface:
enabled:
language-url: -20
language-user: -19
language-browser: -18
language-selected: -17
method_weights:
language-graphql-operation: -15
language-user-admin: -14
language-url: -20
language-session: -16
language-user: -19
language-browser: -18
language-selected: -17
language-session: -16
language-graphql-operation: -15
language-user-admin: -14
_core:
default_config_hash: dqouFqVseNJNvEjsoYKxbinFOITuCxYhi4y2OTNQP_8

View File

@ -1,13 +1,13 @@
extend type Query {
route(path: String!): NodeInterface
route(path: String!, lang: String): NodeInterface
}
extend type Query {
materiau(id: Int!): Materiau
materiau(id: Int!, lang: String): Materiau
}
extend type Query {
materiaux(ids: [Int]): [Materiau]
materiaux(ids: [Int], lang: String): [Materiau]
}
extend type Query {
@ -15,35 +15,35 @@ extend type Query {
}
extend type Query {
article(id: Int!): Article
article(id: Int!, lang: String): Article
}
extend type Query {
thematique(id: Int!): Thematique
thematique(id: Int!, lang: String): Thematique
}
extend type Query {
showroom(id: Int!): Showroom
showroom(id: Int!, lang: String): Showroom
}
extend type Query {
tag(id: Int!): Tag
tag(id: Int!, lang: String): Tag
}
extend type Query {
thesaurus(id: Int!): Thesaurus
thesaurus(id: Int!, lang: String): Thesaurus
}
extend type Query {
company(id: Int!): Company
company(id: Int!, lang: String): Company
}
extend type Query {
product(id: Int!): Product
product(id: Int!, lang: String): Product
}
extend type Query {
products(ids: [Int]): [Product]
products(ids: [Int], lang: String): [Product]
}
# extend type Query {

View File

@ -101,6 +101,7 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
->map('path', $builder->fromArgument('path')),
$builder->produce('route_entity')
->map('url', $builder->fromParent())
->map('language', $builder->fromArgument('lang'))
));
}
@ -113,15 +114,11 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
// $language = \Drupal::languageManager()->getCurrentLanguage()->getId();
$registry->addFieldResolver('Query', 'materiau',
// $builder->compose(
$builder->produce('entity_load')
->map('type', $builder->fromValue('node'))
->map('bundles', $builder->fromValue(['materiau']))
->map('id', $builder->fromArgument('id'))
// ->map('language', $builder->fromValue('fr')),
// $builder->produce('entity_translation')
// ->map('entity', $builder->fromParent())
// )
$builder->produce('entity_load')
->map('type', $builder->fromValue('node'))
->map('bundles', $builder->fromValue(['materiau']))
->map('id', $builder->fromArgument('id'))
->map('language', $builder->fromArgument('lang'))
);
$registry->addFieldResolver('Query', 'materiaux',
@ -129,6 +126,7 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
->map('type', $builder->fromValue('node'))
// ->map('bundles', $builder->fromValue(['materiau']))
->map('ids', $builder->fromArgument('ids'))
->map('language', $builder->fromArgument('lang'))
);
$registry->addFieldResolver('Materiau', 'id',
@ -374,6 +372,7 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
->map('type', $builder->fromValue('node'))
->map('bundles', $builder->fromValue(['article']))
->map('id', $builder->fromArgument('id'))
->map('language', $builder->fromArgument('lang'))
);
$registry->addFieldResolver('Article', 'id',
@ -425,10 +424,37 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
// https://github.com/drupal-graphql/graphql/blob/8.x-4.x/doc/SUMMARY.md
// https://blog.chrismitchellonline.com/posts/custom_graphql_data/
$registry->addFieldResolver('Article', 'linked_materials',
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_linked_materials'))
);
// $builder->produce('entity_reference')
// ->map('entity', $builder->fromParent())
// ->map('field', $builder->fromValue('field_linked_materials'))
// ->map('language', $builder->fromValue('fr')) // this is not working
// // ->map('language', $builder->produce('entity_language')
// // ->map('entity', $builder->fromParent())) // neither that
$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();
$test="test";
return [
"ids" => $nids,
"language" => $lang
];
}),
$builder->produce('entity_load_multiple')
->map('type', $builder->fromValue('node'))
->map('bundles', $builder->fromValue(['materiau']))
->map('ids', $builder->callback(function($parent, $args){
return $parent['ids'];
}))
->map('language', $builder->callback(function($parent, $args){
return $parent['language'];
}))
)
);
$registry->addFieldResolver('Article', 'images',
$builder->produce('entity_reference')

File diff suppressed because one or more lines are too long

View File

@ -29,7 +29,7 @@ export default {
props: ['item'],
data(){
return {
alias: this.item.view_node.replace(/^.?\/blabla\//g, '')
alias: this.item.view_node.replace(/^.*\/blabla\//g, '')
}
},
methods:{

View File

@ -117,7 +117,7 @@ export default {
console.log('loadMaterial', this.item.id)
this.loading = true
let ast = gql`{
materiau(id: ${this.item.id}) {
materiau(id: ${this.item.id}, lang: "${drupalDecoupled.lang_code}") {
...MateriauFields
}
}

View File

@ -213,7 +213,7 @@ export default {
this.loading = true
let ast = gql`{
route(path: "${this.path}") {
route(path: "${this.path}", lang: "${drupalDecoupled.lang_code}") {
...ArticleFields
}
}