doufei2194 2011-12-12 20:13
浏览 39
已采纳

在哪里实现hook_search_info&_execute以强制语言过滤器到搜索结果?

At the moment I am trying to force "current language" onto the list of the options passed into node_search_execute. Unfortunately I'm having trouble finding the right place to put the function hooks. Perhaps I am missing something simple.

I've got myself down to two basic possibilities for how this should be implemented.

(1) Implement hook_search_info and hook_search_execute

In this case, I'd copy the code from node_search_execute and add a line to it that adds "AND Language = '$current_language'" to the search query.

In my theme folder I've tried adding the functions mythemename_search_info and mythemename_search_execute - but they do not execute. When run.

 function mythemename_search_info() {
    return array(
        'title' => 'Content', 
        'path' => 'node', 
        'conditions_callback' => 'mythemename_search_execute',
    );
 }

 function mythemename_search_execute($keys = NULL, $conditions = NULL){
    return array();
 }

In this example - I'd just hope to get "no results" so I could be sure the override was running, then I'd implement the full search functionality.

(2) Implement hook_search_preprocess()

I also tried mythemename_search_preprocess()

 function mythemename_search_preprocess($text) {
   // Do processing on $text
    echo $text; die();
    $text = "french";
   return $text;
 }

But again, I don't get the expected results (a white page with a bit of text on it)

So whatever I'm doing, these search hooks are not getting detected.

What's missing? Do they perhaps have to be in a module?

  • 写回答

2条回答 默认 最新

  • doujiao7483 2011-12-12 23:01
    关注

    Yes they do need to be in a module, most hooks are only called for modules and not themes. The most notable exception to this would be theme/preprocess hooks which are called for both.

    In case you haven't made one before it's pretty straightforward to create a custom module, there's an invaluable guide here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line