在节点“插入”期间获取 Drupal 路径启用 Pathauto 时的操作?
我正在编写一个与 Google Base 交互的模块。它需要插入一个指向该项目所在页面的链接,但是,在 pathauto 运行之前,该项目没有路径。我怎样才能确保pathauto在我的模块之前运行它的钩子,或者获取pathauto产生的路径?
该解决方案需要足够通用,才能与管理员概述的具有不同路径自动设置的任何类型的节点一起使用。
问题是,当我调用该函数时,$node 变量的 [path] 值如下所示: [路径自动执行别名] => 1
节点路径的值显示为空,并且提供给 Google Base 的值只是网站的基本 URL。
有没有办法改变 hook_nodeapi 函数运行的权重,以便它们稍后而不是更快运行?
我遇到了类似的分类问题,没有将术语附加到我试图访问的节点。我通过使用taxonomy_node_get_terms() 解决了这个问题,
提前致谢。
I'm writing a module that interfaces with Google Base. It needs to insert a link to the page that the item is on, however, this item has no path until pathauto runs. How can I either make sure pathauto runs its hooks before my module does, or get the path that will result from pathauto?.
The solution needs to be generic enough to work with any kind of node having different pathauto settings as outlined by the admin.
The problem is that the [path] value for the $node variable looks like the following when I call the function: [path] => [pathauto_perform_alias] => 1
The value for the node path comes out empty, and the value given to Google Base is simply the base-url for the website.
Is there a way to change the weight at which hook_nodeapi functions run, so that they'll run later instead of sooner?
i ran into a similar problem with taxonomy not having attached the terms to the node that I was trying to access. I got around that by using taxonomy_node_get_terms()
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
模块本身有一个权重,决定了调用其钩子实现的顺序。 AFAIK 具有相同权重的模块按字母顺序调用。
如果您在安装时没有明确设置模块的权重(通过 hook_install),它将获得默认权重 0。
如果您需要模块钩子实现在特定其他模块之后运行,例如 pathauto< /em> 你应该在模块 hook_install 实现中执行类似的操作:
注意:模块权重影响所有模块钩子实现的调用顺序与所有其他模块相关!
我不知道影响单个钩子实现调用顺序的方法,因此对于我需要单个钩子实现以特殊顺序运行,而其他需要以特殊顺序运行的情况根据不同的顺序,我最终创建了一个或多个子模块,以允许在不同的钩子实现上进行不同的权重设置。
Modules themselves have a weight that determines the order in which they get called for invocations of their hook implementations. Modules with the same weight get called in alphabetical order, AFAIK.
If you do not explicitly set the weight of your module on installation (via hook_install), it gets the default weight of 0.
If you need your modules hook implementations to run after that of a specific other module, like e.g. pathauto you should do something like this in your modules hook_install implementation:
Beware: The modules weight influences the order in which all of the modules hook implementations get called in relation to all other modules!
I do not know of a way to influence a single hook implementations call order, so for cases where I needed a single hook implementation to run in a special order, while others needed to run in a different order, I ended up creating one or more sub modules to allow for different weight settings on different hook implementations.
是的。这能解决您的问题吗?
Yes. Does that solve your problem?
查看 pathauto 模块中的代码,我看到以下几行可能对您有用。
如果您只想知道 url,您可以将它们复制到您的模块中。还值得注意的是,此代码仅针对 op=='insert' 和 op=='update' 运行。
另一件需要注意的事情是,它调用了 path_set_alias(),它将一个值放入 url_alias 表中。我认为调用 drupal_get_path_alias 会做你想要的。
Looking at the code in the pathauto module I see the following lines which may be of use to you
If you just want to know the url, you could crib these into your module. It is also worth noting that this code is run only for op=='insert' and op=='update'.
Another thing to note on this is that it calls path_set_alias() which puts a value into the url_alias table. I think calling drupal_get_path_alias will do what you want.
钩子的实现是根据模块的权重来执行的。在特定情况下,更改权重不起作用,因为表单字段可能在
hook_form_alter()
或hook_form_FORM_ID_alter()
中更改。The implementations of a hook are executed basing on the weight of the modules. In the specific case, changing the weight could not work because the form fields are probably changed in
hook_form_alter()
orhook_form_FORM_ID_alter()
.我最近也遇到了这个问题,上述答案都没有多大帮助。
我最终使用了这个:
我意识到它完全是一个黑客,但它有效,而且这里没有其他任何东西。
I recently ran into this problem too, and none of the above answers really helped much.
I ended up using this:
I realize its a total hack, but it works, and nothing else here did.