소스 검색

gql getting concernement from entite

bach 1 년 전
부모
커밋
d7b9f4d209

+ 4 - 3
src/config/sync/search_api.index.concernements.yml

@@ -118,7 +118,8 @@ field_settings:
     label: Title
     datasource_id: 'entity:node'
     property_path: title
-    type: string
+    type: text
+    boost: !!float 2
     dependencies:
       module:
         - node
@@ -126,7 +127,7 @@ field_settings:
     label: Title
     datasource_id: 'entity:node'
     property_path: title
-    type: string
+    type: text
     dependencies:
       module:
         - node
@@ -134,7 +135,7 @@ field_settings:
     label: 'Entités » Paragraph » Entité » Contenu » Title'
     datasource_id: 'entity:node'
     property_path: 'field_entite:entity:field_entite:entity:title'
-    type: string
+    type: text
     dependencies:
       config:
         - field.storage.node.field_entite

+ 3 - 2
src/config/sync/search_api.index.entites.yml

@@ -30,7 +30,7 @@ field_settings:
     label: 'Experiences vécues » Paragraph » Liens'
     datasource_id: 'entity:node'
     property_path: 'field_sources:entity:field_liens'
-    type: string
+    type: text
     dependencies:
       config:
         - field.storage.node.field_sources
@@ -85,7 +85,8 @@ field_settings:
     label: Title
     datasource_id: 'entity:node'
     property_path: title
-    type: string
+    type: text
+    boost: !!float 2
     dependencies:
       module:
         - node

+ 1 - 0
src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.base.graphqls

@@ -50,6 +50,7 @@ type Entite implements NodeInterface {
   proximite: [Entite]
   agissante: Boolean
   sources: [Source]
+  concernement: Concernement
 }
 
 type Source {

+ 32 - 0
src/web/modules/custom/ouatt_graphql/src/Plugin/GraphQL/SchemaExtension/OuattSchemaExtension.php

@@ -485,6 +485,38 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase {
         ->map('field', $builder->fromValue('field_sources'))
       );
 
+    $registry->addFieldResolver('Entite', 'concernement',
+      $builder->compose(
+        $builder->callback(function($parent, $arg){
+          $entite_nid = $parent->id();
+          $node_storage = \Drupal::entityTypeManager()->getStorage('node');
+          $paragraph_storage = \Drupal::entityTypeManager()->getStorage('paragraph');
+          $query = $node_storage->getQuery()
+            ->condition('type', ['concernement'], 'IN')
+            // ->condition('uid', $parent->id())
+            ->accessCheck(TRUE);
+          $results = $query->execute();
+          $concernements = [];
+          foreach ($results as $nid) {
+            $concernement = $node_storage->load($nid);
+            $entite_integre_paragraph_values = $concernement->field_entite->getValue();
+            foreach ($entite_integre_paragraph_values as $paragraph_ids) {
+              $paragraph = $paragraph_storage->load($paragraph_ids['target_id']);
+              $field_entite_values = $paragraph->field_entite->getValue();
+              if ($field_entite_values[0]['target_id'] === $entite_nid) {
+                $concernements[] = $nid;
+                break;
+              }
+            }
+          }
+          return $concernements[0];
+        }),
+        $builder->produce('entity_load')
+          ->map('type', $builder->fromValue('node'))
+          ->map('id', $builder->fromParent())
+      )
+    );
+
   }
 
   //   ____