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

发布于 2024-12-20 15:19:13 字数 1223 浏览 2 评论 0原文

目前,我正在尝试将“当前语言”强制添加到传递给 node_search_execute 的选项列表中。不幸的是,我无法找到放置函数挂钩的正确位置。也许我错过了一些简单的事情。

对于如何实现这一点,我已经总结出了两种基本的可能性。

(1) 实现 hook_search_infohook_search_execute

在这种情况下,我会从 node_search_execute 复制代码并添加将“AND Language = '$current_language'”添加到搜索查询中。

在我的主题文件夹中,我尝试添加函数 mythemename_search_infomythemename_search_execute - 但它们不执行。运行时。

 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();
 }

在这个例子中 - 我只是希望得到“没有结果”,这样我就可以确定覆盖正在运行,然后我将实现完整的搜索功能。

(2) 实现 hook_search_preprocess()

我也尝试过 mythemename_search_preprocess()

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

但同样,我没有得到预期的结果(带有上面有一些文字)

所以无论我在做什么,这些搜索挂钩都不会被检测到。

缺少什么?它们是否必须位于模块中?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

_畞蕅 2024-12-27 15:19:13

是的,它们确实需要位于模块中,大多数钩子仅针对模块而不是主题调用。最值得注意的例外是主题/预处理挂钩,两者都会被调用。

如果您以前没有制作过自定义模块,那么创建自定义模块非常简单,此处有一份非常宝贵的指南。

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.

污味仙女 2024-12-27 15:19:13

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文