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_workflow
- field_migration - field_migration
- field_memo - field_memo
- translation
parent_name: '' parent_name: ''
weight: 1 weight: 1
format_type: tab format_type: tab
@ -240,12 +241,13 @@ content:
placeholder: '' placeholder: ''
third_party_settings: { } third_party_settings: { }
translation: translation:
weight: 3 weight: 7
region: content region: content
settings: { } settings: { }
third_party_settings: { } third_party_settings: { }
hidden: hidden:
created: true created: true
flag: true
path: true path: true
promote: true promote: true
status: true status: true

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

File diff suppressed because one or more lines are too long

View File

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

View File

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

View File

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