Drupal hook_views_post_execute not getting called

拥有回忆 提交于 2019-12-10 14:15:50

问题


I'm trying to hook into the hook_views_post_execute event in Drupal 7, my module called foo is located in sites/default/modules/features/foo.

My foo.module file contains a definition for the hook_views_api function, defined like this:

function foo_views_api() {
    return array("version" => 3.0);
}

This function gets called, but my implementation of the hook_views_post_execute does not, it's defined (in the same foo.module file) like this:

function foo_views_post_execute(&$view) {

    $seen_rows = array();
    $newResults = array();

    for($i = 0; $i < count($view->result); ++$i) {
        if (!in_array($view->result[$i]->nid, $seen_rows)) {
            $newResults[] = $view->results[$i];
        }

        $seen_rows[] = $view->result[$i]->nid;
    }

    $view->result = $newResults;

}

I've been over the drupal API/hooks documentation, googled and read every blog post I've been able to find. I just can't get it to work. The hook does not get called. I'm assuming I've done something simple wrong since I'm not a drupal developer or PHP developer normally.


回答1:


The view has probably been cached so it doesn't go through that function.

Go to the top left and clear the cache and you should see the result.



来源:https://stackoverflow.com/questions/5844148/drupal-hook-views-post-execute-not-getting-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!