Created
June 4, 2013 08:15
-
-
Save GoZOo/5704400 to your computer and use it in GitHub Desktop.
Drupal code: Exclude some content types from node search
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(). | |
| * Exclude some content types from node search | |
| * Ne pas prendre en compte certains types de contenu dans la recherche | |
| */ | |
| function mymodule_query_node_access_alter(QueryAlterableInterface $query) { | |
| global $user; | |
| // No exclude for super admin | |
| if ($user->uid == 1) { | |
| return; | |
| } | |
| $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) { | |
| $excluded_content_types = array('contenttype1', 'contenttype2', 'contenttype3'); | |
| // A core bug results in a DB error if we use the following: Ref: #1210072 | |
| $query->condition($node . '.type', array($excluded_content_types), 'NOT IN'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment