2

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?

4

2 回答 2

3

是的,它们确实需要在一个模块中,大多数钩子只为模块而不是主题调用。最值得注意的例外是主题/预处理钩子,它们都被调用。

如果您在创建自定义模块非常简单之前还没有制作过,这里有一个非常宝贵的指南

于 2011-12-12T23:01:13.417 回答
1

我使用hook_search_info(),hook_search_execute()hook_search_access()在我的自定义模块中。用模块名称替换“钩子”。我能够获得使用“标题”创建的选项卡hook_search_info()。并在 hook_search_execute 中传递了他的结果数组。这样,结果开始显示在搜索页面的选项卡下。因此,绝对创建一个新模块将有助于包含一个新的搜索选项卡。

于 2012-08-14T15:23:35.893 回答