Last active
December 28, 2015 02:59
-
-
Save opi/7431393 to your computer and use it in GitHub Desktop.
Drupal 7 : Restrict searchable 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'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment