restrict base search and default base to current language
This commit is contained in:
parent
820bfcf85a
commit
651315c319
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue