Drupal hook_views_post_execute 没有被调用
我正在尝试挂钩 Drupal 7 中的 hook_views_post_execute
事件,我的名为 foo
的模块位于 sites/default/modules/features/foo
。
我的 foo.module
文件包含 hook_views_api
函数的定义,定义如下:
function foo_views_api() {
return array("version" => 3.0);
}
此函数被调用,但我的 hook_views_post_execute
实现确实如此不,它是这样定义的(在同一个 foo.module 文件中):
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;
}
我已经浏览了 drupal API/hooks 文档,用谷歌搜索并阅读了我能找到的每一篇博客文章。我就是无法让它发挥作用。钩子不会被调用。我假设我犯了一些简单的错误,因为我通常不是 drupal 开发人员或 PHP 开发人员。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(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.