How can I run a query in the views in the context of the user? E.g. using EntityFieldQuery I can run

$query->addMetaData('account', user_load(1));

is there any equivalent for $view->query?


I've found possibility to do it in hook_views_post_build:

function MY_MODYLE_views_post_build($view) {
  if($view->name == 'MY_VIEW_NAME') {
    $query = $view->build_info['query'];
    $query->addMetaData('account', user_load(47));

I've noticed that we have SelectQuery object only after query build (in views.inc $this->query->build($this);).

After it only one hook is executed views_post_build.

|improve this answer|||||

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.