Frage

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?

War es hilfreich?

Lösung

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.

Andere Tipps

I used hook_search_info(), hook_search_execute() and hook_search_access() in my custom module. replaced "hook" with module name. I was able to get the tab created with 'title' of hook_search_info(). and passed he results array in hook_search_execute. with this the results started showing under the tab in search page. So definitely creating a new module will be of help to get a new search tab included.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top