Jelajahi Sumber

restrict base search and default base to current language

bach 4 tahun lalu
induk
melakukan
651315c319
1 mengubah file dengan 5 tambahan dan 2 penghapusan
  1. 5 2
      web/modules/custom/materio_sapi/src/Controller/Base.php

+ 5 - 2
web/modules/custom/materio_sapi/src/Controller/Base.php

@@ -87,7 +87,8 @@ class Base extends ControllerBase {
     }
 
     // Restrict the search to specific languages.
-    // $this->query->setLanguages(['de', 'it']);
+    $lang = \Drupal::languageManager()->getCurrentLanguage()->getId();
+    $this->query->setLanguages([$lang]);
 
     // Do paging.
     $this->query->range($this->offset, $this->limit);
@@ -105,10 +106,12 @@ class Base extends ControllerBase {
   }
 
   private function defaultQuery(){
+    $lang = \Drupal::languageManager()->getCurrentLanguage()->getId();
     $entity_storage = \Drupal::entityTypeManager()->getStorage('node');
     $this->query = $entity_storage->getQuery()
       ->condition('type', ['materiau', 'thematique'], 'IN')
       ->condition('status', '1')
+      ->condition('langcode', $lang)
       ->range($this->offset, $this->limit)
       ->accessCheck(TRUE)
       ->sort('changed', 'DESC');
@@ -117,6 +120,7 @@ class Base extends ControllerBase {
 
     $this->count_query = $entity_storage->getQuery()
       ->condition('type', ['materiau', 'thematique'], 'IN')
+      ->condition('langcode', $lang)
       ->accessCheck(TRUE)
       ->condition('status', '1')
       ->count();
@@ -198,7 +202,6 @@ class Base extends ControllerBase {
         // Load a single node.
         // $node = $node_storage->load($result);
         // check if has translation
-
         // i used to filter like bellow because of a graphql probleme
         // if ($node->hasTranslation($lang)) {
           $nids[] = $result;