From 651315c3191c0ce77c15973e5bde1cd6ce837e22 Mon Sep 17 00:00:00 2001 From: bach Date: Fri, 5 Mar 2021 21:32:59 +0100 Subject: [PATCH] restrict base search and default base to current language --- web/modules/custom/materio_sapi/src/Controller/Base.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/web/modules/custom/materio_sapi/src/Controller/Base.php b/web/modules/custom/materio_sapi/src/Controller/Base.php index 0d7fff31..e56f3051 100644 --- a/web/modules/custom/materio_sapi/src/Controller/Base.php +++ b/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;