restrict base search and default base to current language

This commit is contained in:
Bachir Soussi Chiadmi 2021-03-05 21:32:59 +01:00
parent 820bfcf85a
commit 651315c319
1 changed files with 5 additions and 2 deletions

View File

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