0

I need to filter a table result based the current user.

I added this condition in my hook_views_query_alter

function my_module_views_query_alter(&$view, &$query) {
  global $user;
  if ($view->name == 'preventivi' && $view->current_display == 'page_3') 
  {
    // $view->query->add_where(1, $user->uid, 33, '=');
    $view->query->add_where(1, "field_data_field_installatori_reference.field_installatori_reference_target_id", $user->uid, '!=');

    // dpm($view);
    //dpm($query);
  }
}

but I can't find the correct value of target_id to insert in the condition. Any suggestion?

1
  • What version of drupal
    – AlxVallejo
    Mar 10 at 22:30
0

This comment save my life! https://api.drupal.org/comment/49458#comment-49458

Be careful to add the table, even if You added the field in the view UI :

I added

$view->query->add_table("field_data_field_installatori_reference");

and then I could access to my field:

$view->query->add_where(1, "field_data_field_installatori_reference.field_installatori_reference_target_id", $user->uid, '!=');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.