1

I have a view who display several nodes (more than 10 000), and I display 100 nodes by pages. With a HOOK_views_pre_render(&$view) I browse all the results $view->result and I unset the nodes which I haven't access with a personnal function like this :

if (!empty($view->result)) {
    if ($view->name == 'vdocuments' && $view->current_display == 'page') {
        foreach ($view->result as $key => $lineView) {
            if (!empty($lineView->nid)) {
                $lineAllowed = _isNodeAllowedToUser($lineView->nid);
                if (empty($lineAllowed) || !$lineAllowed) {
                    //$counter++;
                    unset($view->result[$key]);
                }
            }
        }
    }
}

My first question concern this code. Is there a better method to remove some results in my wiew (I need to use my check function) ? I tried to alter the query of the view and check the NID allowed in a filter, but there is too much NID to remove for certain users.

So, the code above remove all the bad nodes in the page i'm viewing, but all the pagination is destroyed, on several pages I have empty results.

I found this page https://www.drupal.org/node/953072#comment-6317230 but the update_page_info doesn't work really good.

Is there a solution to get all the nodes "allowed" and calculate the pagination with the rest of the nodes after the unset ?

thanks

  • I tried to unset my results in HOOK_views_post_execute like this post said drupal.stackexchange.com/questions/95448/… but this not working.. Nobody have an solution for the problem ? – Cracs Nov 10 '16 at 15:40
  • A little up for my post because I haven't found any solutions since november. – Cracs Jan 10 '17 at 13:06

Your Answer

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

Browse other questions tagged or ask your own question.