-
-
Save flocondetoile/9091f66cd3fe1a39ded3 to your computer and use it in GitHub Desktop.
Drupal 7 Search language and content type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements of hook_query_node_access_alter(). | |
*/ | |
function MYMODULE_query_node_access_alter(QueryAlterableInterface $query) { | |
$search = FALSE; | |
$node = FALSE; | |
foreach ($query->getTables() as $alias => $table) { | |
if ($table['table'] == 'search_index') { | |
$search = $alias; | |
} | |
elseif ($table['table'] == 'node') { | |
$node = $alias; | |
} | |
} | |
if ($node && $search) { | |
// Searchable node types | |
$allowed_type = array( | |
'content_type_1', | |
'content_type_2' | |
); | |
$query->condition($node . '.type', $allowed_type, 'IN'); | |
// Search language | |
$db_and = db_and(); | |
// I guess you *could* use global $language here instead but this is safer. | |
$language = i18n_language_interface(); | |
$lang = $language->language; | |
$db_and->condition($node . '.language', $lang, '='); | |
$query->condition($db_and); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment