Perform a node search by current language

Created on 8 October 2018, about 6 years ago
Updated 2 July 2024, 4 months ago

API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Database%...

In some projects i found the need to perform the classic node search based on the current language that user is visiting the website, so i guess it would be nice to include some option to filter by language on the search configuration.

This is a simple contribution for someone who is in need to the same that i did some days ago:

function hook_query_search_node_search_alter(&$query) {
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
$query->condition('i.langcode', array($language, 'und', 'zxx'), 'IN');
}

✨ Feature request
Status

Closed: outdated

Version

11.0 πŸ”₯

Component
SearchΒ  β†’

Last updated 1 day ago

  • Maintained by
  • πŸ‡ΊπŸ‡ΈUnited States @pwolanin
Created by

πŸ‡΅πŸ‡ΉPortugal joao.ramos.costa

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024