Drupal的模块钩子调用从哪里开始?

发布于 2024-10-17 06:46:02 字数 880 浏览 0 评论 0原文

在 Drupal 7(和 Drupal 6?)系统中,什么“启动”挂钩调用过程,或者“顶级”挂钩调用位于何处?

据我目前了解的 Drupal 模块系统,任何模块都能够为另一个模块创建一个钩子来实现。这意味着 Drupal 的大部分执行都是为其他模块实现钩子的模块,而其他模块又为其他模块提供要实现的钩子。

我不清楚的是,是否有一个初始的、顶级的钩子在引导程序中被调用来启动这个过程,或者是否有几个非模块调用启动了钩子调用过程,或者其他什么(抱歉这是模糊和新奇的,但就像我说的我不明白)

我查看了 _drupal_bootstrap_full 函数,最后有一个有希望的

module_invoke_all('init');

但是,我搜索了 modules/ 文件夹只出现了一个“init”钩子函数,这似乎不是一个启动点

system/system.api.php
1737:function hook_init() {

function hook_init() {
  drupal_add_css(drupal_get_path('module', 'book') . '/book.css');
}

所以,这对我来说是模块系统之外的一些东西启动了整个事情。这种情况是发生在一个地方,还是多个地方。这些地方在哪里?

我目前不是 Drupal 的重度用户。我所有这一切的最终目标是单独了解 Drupal 的模块系统,以便我可以研究并了解 Drupal 如何使用其模块来构建大多数人认为是 Drupal 的应用程序。欢迎任何/所有解释,但我试图从架构的角度理解事物。我知道您不需要这些知识来使用 Drupal,但我的大脑已经坏了,在我知道基本 PHP 代码在做什么之前不会让我继续前进。

In a Drupal 7 (and Drupal 6?) system, what "kicks off" the hook calling process, or where are "top level" hook calls located?

As I currently understand the Drupal module system, any module is capable of creating a hook for another module to implement. That means much of Drupal's execution is modules implementing hooks for other modules, which in turn provide hooks for other modules to implement.

What I'm not clear on is if there's a initial, top level hook that gets called in the bootstrap to kick this process off, or if there's several non-module calls that kick-off the hook invoking process, or something else (apologies is this is vague and newbish, but like I said I don't understand)

I looked in the _drupal_bootstrap_full function, and at the end there was a promising

module_invoke_all('init');

However, my search of the modules/ folder only turned up one "init" hook function, which didn't appear to be a kick off point

system/system.api.php
1737:function hook_init() {

function hook_init() {
  drupal_add_css(drupal_get_path('module', 'book') . '/book.css');
}

So, that says to me something outside the module systems kicks this whole things off. Does this happen in a single place, or multiple places. And where are these places?

I'm not currently a heavy Drupal user. My end goal of all this is understanding Drupal's module system in isolation, so that I can then investigate and understand how Drupal uses it's modules the build the application most people think of as Drupal. Any/all explanations are welcome, but I'm trying to understand things from an architectural point of view. I understand you don't need this knowledge to use Drupal, but my brain is broken and won't let me move forward until I know what the base PHP code is doing.

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

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

发布评论

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

评论(2

靑春怀旧 2024-10-24 06:46:02

钩子系统是 Drupal 内部的一个独立系统。它不负责引导。 hook_init() 只是在引导过程结束时调用的钩子。正如另一个答案所说, module_invoke_all() 可以在进程中随时随地调用。

简而言之,在 Drupal 7 中,index.php 中的以下两行负责请求的基本流程:

<?php
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
menu_execute_active_handler();
?>

这可以翻译为两个步骤:

  1. 引导系统。这包括加载所有模块和必要的包含文件、数据库连接等。

  2. 查找负责此请求的菜单路由器项并执行它。

有人开始了一系列博客文章来更详细地描述它,请参阅http://becircle.com/blog_topics/line_line< /a>.

The hook system is one separated system inside of Drupal. It is not responsible for the bootstrapping. hook_init() is just the hook that is called at the end of the bootstrap process. As the other answer said, module_invoke_all() can be called anytime, anywhere in the process.

Put simply, in Drupal 7, the following two lines in index.php are responsible for the very basic flow of a request:

<?php
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
menu_execute_active_handler();
?>

Which can be translated into two steps:

  1. Bootstrap the system. This includes loading all modules and necessary include files, database connection and so on.

  2. Look for the menu router item responsible for this request and execute it.

Someone started a series of blog post to describe it in more details, see http://becircle.com/blog_topics/line_line.

坠似风落 2024-10-24 06:46:02

module_invoke_all 是这一切发生的地方。

来自文档:在实现它的所有启用的模块中调用一个钩子。

Init 可能不是一个好的钩子,因为很少有人定义它。另外,请记住,钩子称为 而不是 hook

编辑:

/**
 * Deletes a node type from the database.
 *
 * @param $type
 *   The machine-readable name of the node type to be deleted.
 */
function node_type_delete($type) {
  $info = node_get_types('type', $type);
  db_query("DELETE FROM {node_type} WHERE type = '%s'", $type);
  module_invoke_all('node_type', 'delete', $info);
}

这是在 D6 node.module 中。这是从模块代码调用挂钩的示例,在本例中为 hook_node_type,带有两个参数。

module_invoke_all is where it all happens.

From the doc: Invoke a hook in all enabled modules that implement it.

Init probably isn't a good one as very few define it. Also, remember that hooks are called and not hook.

Edit:

/**
 * Deletes a node type from the database.
 *
 * @param $type
 *   The machine-readable name of the node type to be deleted.
 */
function node_type_delete($type) {
  $info = node_get_types('type', $type);
  db_query("DELETE FROM {node_type} WHERE type = '%s'", $type);
  module_invoke_all('node_type', 'delete', $info);
}

This is in D6 node.module. This is an example of invoking a hook from module code, in this case hook_node_type, with two arguments.

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