Created
September 22, 2014 19:54
-
-
Save isramv/eb5f989a2eae78c458fd to your computer and use it in GitHub Desktop.
Views Query Alter for Drupal example.
This file contains 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 hook_views_query_alter(); | |
* | |
*/ | |
function custom_partnerportal_views_query_alter(&$view, &$query) { | |
if ($view->name == 'taxonomy_term') { | |
global $user; | |
$usuario = user_load($user->uid); | |
$categories = $usuario->field_category['und']; | |
$cats = array(); | |
foreach($categories as $item) { | |
$cats[] = $item['tid']; | |
} | |
$actualarguments = $view->args; | |
$result_array = array_diff($actualarguments,$cats); | |
$countdif = count($result_array); | |
if($countdif == 0) { | |
} else { | |
$view->executed = TRUE; | |
drupal_set_message(t('You dont have access to this content.'),'error'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment