Where does the "Connect to Drupal Interface" call begin?

In Drupal 7 (and Drupal 6?), What triggers the hook call process, or where are the top-level hooks?

As I understand the Drupal module system, any module is able to create a hook for the implementation of another module. This means that most of Drupal's execution is modules that implement hooks for other modules, which in turn provide hooks for other modules for implementation.

I don’t understand if there is a top-level initial hook that is called in the bootstrap to disable this process or if there are several non-modular calls that start the hook call process or something else (apologies is uncertain and new, but as I already 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, in my search in the modules/ folder, there was only one function called β€œinit” hook, which did not seem to be a launch point

 system/system.api.php 1737:function hook_init() { function hook_init() { drupal_add_css(drupal_get_path('module', 'book') . '/book.css'); } 

So, this tells me that something outside of modular systems discards it all. This happens in one place or in several places. And where are these places?

I am currently not a heavy Drupal user. My ultimate goal here is to understand the Drupal module system in isolation , so I can then research and understand how Drupal uses its modules, building an application that 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 that you do not need this knowledge to use Drupal, but my brain is broken and will not allow me to move forward until I find out what the basic PHP code does.

+4
source share
2 answers

The hook system is one separate system within Drupal. He is not responsible for the download. hook_init () is just a hook that is called at the end of the boot process. As another answer said, module_invoke_all () can be called anytime, anywhere in the process.

Simply put, in Drupal 7, the following two lines in index.php are responsible for the most basic request stream:

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

What can be translated into two stages:

  • Boot the system. This includes downloading all modules and necessary files, connecting to a database, etc.

  • Find the menu router item responsible for this request and execute it.

Someone started a series of blog posts to describe them in more detail, see http://becircle.com/blog_topics/line_line .

+5
source

module_invoke_all is where all this happens.

From the document: call the hook in all allowed modules that implement it.

The initiator is probably not very good, as few people define him. Also, remember that hooks are called, not hooked.

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 the D6 node module. This is an example of calling hook from module code, in this case hook_node_type with two arguments.

0
source

Source: https://habr.com/ru/post/1339722/


All Articles