在节点“插入”期间获取 Drupal 路径启用 Pathauto 时的操作?

发布于 2024-08-02 05:30:15 字数 440 浏览 8 评论 0原文

我正在编写一个与 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 技术交流群。

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

发布评论

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

评论(5

放肆 2024-08-09 05:30:15

有没有办法改变重量
运行哪些 hook_nodeapi 函数,所以
他们会稍后运行而不是
更快吗?

模块本身有一个权重,决定了调用其钩子实现的顺序。 AFAIK 具有相同权重的模块按字母顺序调用。

如果您在安装时没有明确设置模块的权重(通过 hook_install),它将获得默认权重 0。

如果您需要模块钩子实现在特定其他模块之后运行,例如 pathauto< /em> 你应该在模块 hook_install 实现中执行类似的操作:

// Get the weight of the module you need to run after/before
$pathauto_weight = db_result(db_query("SELECT weight FROM {system} WHERE name = 'pathauto'"));
// Define your modules weight relative to that
$yourModule_weight = $pathauto_weight + 1;
// Set your modules weight
db_query("UPDATE {system} SET weight = %d WHERE name = 'yourModule'", $yourModule_weight);

注意:模块权重影响所有模块钩子实现的调用顺序与所有其他模块相关!

我不知道影响单个钩子实现调用顺序的方法,因此对于我需要单个钩子实现以特殊顺序运行,而其他需要以特殊顺序运行的情况根据不同的顺序,我最终创建了一个或多个子模块,以允许在不同的钩子实现上进行不同的权重设置。

Is there a way to change the weight at
which hook_nodeapi functions run, so
that they'll run later instead of
sooner?

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:

// Get the weight of the module you need to run after/before
$pathauto_weight = db_result(db_query("SELECT weight FROM {system} WHERE name = 'pathauto'"));
// Define your modules weight relative to that
$yourModule_weight = $pathauto_weight + 1;
// Set your modules weight
db_query("UPDATE {system} SET weight = %d WHERE name = 'yourModule'", $yourModule_weight);

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.

枫林﹌晚霞¤ 2024-08-09 05:30:15

有没有办法改变重量
运行哪些 hook_nodeapi 函数,所以
他们会稍后运行而不是
更快吗?

是的。这能解决您的问题吗?

Is there a way to change the weight at
which hook_nodeapi functions run, so
that they'll run later instead of
sooner?

Yes. Does that solve your problem?

听不够的曲调 2024-08-09 05:30:15

查看 pathauto 模块中的代码,我看到以下几行可能对您有用。

 if (!isset($node->pathauto_perform_alias) || $node->pathauto_perform_alias) {
        $placeholders = pathauto_get_placeholders('node', $node);
        $src = "node/$node->nid";
        $alias = pathauto_create_alias('node', $op, $placeholders, $src, $node->nid, $node->type, $node->language);
      }

如果您只想知道 url,您可以将它们复制到您的模块中。还值得注意的是,此代码仅针对 op=='insert' 和 op=='update' 运行。

另一件需要注意的事情是,它调用了 path_set_alias(),它将一个值放入 url_alias 表中。我认为调用 drupal_get_path_alias 会做你想要的。

$path = 'node/'. $node->nid;
$alias = drupal_get_path_alias($path);

Looking at the code in the pathauto module I see the following lines which may be of use to you

 if (!isset($node->pathauto_perform_alias) || $node->pathauto_perform_alias) {
        $placeholders = pathauto_get_placeholders('node', $node);
        $src = "node/$node->nid";
        $alias = pathauto_create_alias('node', $op, $placeholders, $src, $node->nid, $node->type, $node->language);
      }

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.

$path = 'node/'. $node->nid;
$alias = drupal_get_path_alias($path);
浮生面具三千个 2024-08-09 05:30:15

钩子的实现是根据模块的权重来执行的。在特定情况下,更改权重不起作用,因为表单字段可能在 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() or hook_form_FORM_ID_alter().

失而复得 2024-08-09 05:30:15

我最近也遇到了这个问题,上述答案都没有多大帮助。
我最终使用了这个:

$alias = str_replace(' ', '-', strtolower($node->title));

我意识到它完全是一个黑客,但它有效,而且这里没有其他任何东西。

I recently ran into this problem too, and none of the above answers really helped much.
I ended up using this:

$alias = str_replace(' ', '-', strtolower($node->title));

I realize its a total hack, but it works, and nothing else here did.

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