Browse Source

fixed graphql linked_materials entity_reference translation

bach 3 years ago
parent
commit
2cf2f378ce

+ 3 - 1
config/sync/core.entity_form_display.node.article.default.yml

@@ -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

+ 1 - 1
config/sync/field.field.node.article.body.yml

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

+ 4 - 0
config/sync/field.storage.node.body.yml

@@ -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

+ 1 - 1
config/sync/language.content_settings.node.article.yml

@@ -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

+ 1 - 1
config/sync/language.negotiation.yml

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

+ 3 - 4
config/sync/language.types.yml

@@ -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

+ 11 - 11
web/modules/custom/materio_graphql/graphql/materio_extension.extension.graphqls

@@ -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 {

+ 39 - 13
web/modules/custom/materio_graphql/src/Plugin/GraphQL/SchemaExtension/MaterioSchemaExtension.php

@@ -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 it is too large
+ 0 - 0
web/themes/custom/materiotheme/assets/dist/main.js


+ 1 - 1
web/themes/custom/materiotheme/vuejs/components/Content/ArticleCard.vue

@@ -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:{

+ 1 - 1
web/themes/custom/materiotheme/vuejs/components/Content/ModalCard.vue

@@ -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
         }
       }

+ 1 - 1
web/themes/custom/materiotheme/vuejs/components/Pages/Article.vue

@@ -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
         }
       }

Some files were not shown because too many files changed in this diff