Skip to content

Instantly share code, notes, and snippets.

@isramv
Created September 22, 2014 19:54
Show Gist options
  • Save isramv/eb5f989a2eae78c458fd to your computer and use it in GitHub Desktop.
Save isramv/eb5f989a2eae78c458fd to your computer and use it in GitHub Desktop.
Views Query Alter for Drupal example.
<?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