搜索挂钩无法正常工作

发布于 2024-09-12 08:17:02 字数 735 浏览 0 评论 0原文

我正在尝试使用 hook_search 来扩展内置的 drupal 搜索以显式链接两种内容类型。

前任。项目 a 和 b 是集合 a 的一部分。目前,如果您搜索集合 a 的标题,您只会得到集合 a。我想扩展搜索范围,以便您获得项目 a & b 也因为它们是该集合的成员。

我的代码目前看起来像:

/** Implementation of hook_search() **/
function event_collection_search($op = 'search', $keys = NULL){
    var_dump($keys); echo '<--keys value';


    switch ($op) {
        case 'search':
            echo 'is this case statement being executed?';
            die; //MORE CODE BELOW BUT IT'S BROKEN BY THIS POINT ALREADY

现在我的代码不会进入“搜索”情况,而且我还注意到键为 NULL?我做错了什么?如何扩展搜索或至少访问我正在搜索的值?

编辑:我故意叫“死”。目前,我希望无论是否命中搜索案例,都会回显键值。理想情况下,我希望看到“此案例语句是否正在执行”得到回显,以便我知道搜索案例正在运行。现在 NULL 是键值,第二个字符串没有回显给我。我当前仅获取集合节点的结果,而不是链接到集合节点的两个项目。

I'm trying to use hook_search to extend the built in drupal search to explicitly link two content types.

ex. items a and b are part of collection a. Currently if you search for the title of collection a you only get collection a. I'd like to extend the search so that you get items a & b as well because they are members of that collection.

My code currently looks like:

/** Implementation of hook_search() **/
function event_collection_search($op = 'search', $keys = NULL){
    var_dump($keys); echo '<--keys value';


    switch ($op) {
        case 'search':
            echo 'is this case statement being executed?';
            die; //MORE CODE BELOW BUT IT'S BROKEN BY THIS POINT ALREADY

Right now my code is not going into the 'search' case and also I'm noticing that keys is NULL? What am I doing wrong? How do I extend the search or at the very least access the values I'm searching on?

EDIT: I'm calling 'die' on purpose. Currently I'm expecting the key value to be echoed regardless if the search case is hit or not. Ideally I'd like to see 'is this case statement being executed' echoed as well so I know that the search case is working. Right now NULL is the key value, and the second string is not being echoed back to me. I'm currently only getting the result of the collection node, but not the two items that I have linked to the collection node.

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

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

发布评论

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

评论(2

春庭雪 2024-09-19 08:17:02

您是否查看过http://drupal.org/project/Custom_Search?不确定它是否适合您,但听起来它可以满足您的需要。

Have you looked into http://drupal.org/project/Custom_Search? Not sure if it will be for you but it sounds like it does what you need.

彻夜缠绵 2024-09-19 08:17:02

Drupal 不使用不返回 hook_search('name') 值的搜索挂钩。

我不确定您是否可以使用 echo 来测试 hook_search('search') 是否被调用;如果您调用 die(),您就不可能看到任何内容,因为您在 Drupal 呈现搜索结果之前中断了它的执行。

Drupal doesn't use a search hook that doesn't return a value for hook_search('name').

I am not sure that you can use echo to test if hook_search('search') is being invoked; if then you are calling die(), it's rather impossible you are seeing anything, as you are interrupting the execution of Drupal before it can render the search results.

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