安装和卸载模块时运行的 Drupal 钩子?

发布于 2024-10-28 09:39:11 字数 312 浏览 1 评论 0原文

我正在尝试让 Drupal 运行自定义挂钩;一个需要在安装模块时运行,另一个需要在模块卸载时运行。是否有一个钩子或触发器可以让 Drupal 在安装或卸载模块时运行该钩子?我需要运行的钩子从数组构建分类术语。我的布局基于 hook_schema。该挂钩的实现示例如下:

function mymodule_install_taxonomy() {
    return array(
         <<Taxonomy Structure Here>>
    );
}

该代码将放置在 .install 文件中。

I am trying to get a Drupal to run a custom hooks; one that needs to run when a module is being installed and another for when the module is being unistalled. Is there a hook or a trigger that I can use to have Drupal run the hook while the module is installing or uninstalling? The hook that I need to run builds taxonomy terms from an array. I am basing the lay out on the hook_schema. An example of the implementation of this hook is:

function mymodule_install_taxonomy() {
    return array(
         <<Taxonomy Structure Here>>
    );
}

This code would be placed in the .install file.

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

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

发布评论

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

评论(1

初熏 2024-11-04 09:39:11

什么时候安装你自己的模块还是其他人的模块?

对于您自己的,有 hook_install () (仅在第一次安装模块时调用,通常用于安装 Drupal 6 中 hook_schema() 中定义的模式,这在 Drupal 7 中是自动执行的),hook_uninstall(), hook_enable() (每次启用模块时调用)最后hook_disable()(当您的模块被禁用时)。

Drupal 7 还添加了一组类似的钩子,但在安装、卸载、启用或禁用其他模块时会调用这些钩子,请参阅hook_modules_*()

When your own module is installed or for others?

For your own, there is hook_install() (only called the first time your module is installed, usually used to install the schema defined in hook_schema() in Drupal 6, this is automated in Drupal 7), hook_uninstall(), hook_enable() (called every time your module is enabled) and finally hook_disable() (when your module is disabled).

Drupal 7 has also added a similar set of hooks that is however called when other modules are installed, uninstalled, enabled or disabled, see hook_modules_*()

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