The sequence of Drupal Hooks Alter

Source: Internet
Author: User
Tags drupal

The essence of the Drupal system is the Hooks (hook) design. When there are multiple modules in the system, what is the order of the module alter hooks? With this question, we found the correct answer: Drupal module weight directly affects the execution sequence of hooks in the module. By default, weight of each module is 0, the order method is based on the module name, which is easily influenced by the order of the module name.

Update module Weight
In Drupal 7, weight of the module can be flexibly modified and implemented through hook_module_implements_alter () hook.

The code is as follows: Copy code

<? Php
/**
* Implements hook_module_implements_alter ().
*/
Function custommodule_module_implements_alter (& $ implementations, $ hook ){
If (in_array ($ hook, array ('form _ alter '))){
// Move our hook implementation to the bottom.
$ Group = $ implementations ['custommodule'];
Unset ($ implementations ['custommodule']);
$ Implementations ['custommodule'] = $ group;
}
}
?>

When another method is compatible with all Drupal versions, hook_install is in the custom_module.install file.


Note: When using hook_install, you need to delete the module in the background, and then re-enable the module to take effect.

The code is as follows: Copy code

<? Php
Function your_module_name_install (){
Db_update ('system ')
-> Fields (array ('weight' => your_preferred_weight ))
-> Condition ('name', '[your_module_name]', '= ')
-> Execute ();
}
?>

You can also directly update the database through a code snippet.

The code is as follows: Copy code

<? Php
Db_query ("UPDATE {system} SET weight = [your_preferred_weight] WHERE type = 'module' AND name = '[your_module_name]'");
?>

You can also modify it through a third-party module. You can use the Utility module and the Modules weight module.

Drupal system module list (including name and weight ):

+ ---------------------------- + -------- +
| Name | type | status | weight |
+ ---------------------------- + -------- +
| Strongarm | module | 1 |-1000 |
| Block | module | 1 |-5 |
| Webform | module | 1 |-1 |
| Backup_migrate | module | 1 | 0 |
| Colorbox | module | 1 | 0 |
| Contextual | module | 1 | 0 |
| Crumbs | module | 1 | 0 |
| Ctools | module | 1 | 0 |
| Date | module | 1 | 0 |
| Date_api | module | 1 | 0 |
| Date_views | module | 1 | 0 |
| Entity | module | 1 | 0 |
| Faq | module | 1 | 0 |
| Field | module | 1 | 0 |
| Field_ui | module | 1 | 0 |
| File | module | 1 | 0 |
| Filter | module | 1 | 0 |
| Image | module | 1 | 0 |
| Libraries | module | 1 | 0 |
| Link | module | 1 | 0 |
| List | module | 1 | 0 |
| Locale | module | 1 | 0 |
| Masquerade | module | 1 | 0 |
| Menu | module | 1 | 0 |
| Menu_block | module | 1 | 0 |
| Node | module | 1 | 0 |
| Options | module | 1 | 0 |
| Path | module | 1 | 0 |
| Print | module | 1 | 0 |
| Search | module | 1 | 0 |
| Shortcut | module | 1 | 0 |
| Taxonomy | module | 1 | 0 |
| Taxonomy_manager | module | 1 | 0 |
| Text | module | 1 | 0 |
| Token | module | 1 | 0 |
| Translation | module | 1 | 0 |
| Transliteration | module | 1 | 0 |
| Update | module | 1 | 0 |
| User | module | 1 | 0 |
| Views_ui | module | 1 | 0 |
| Wysiwyg | module | 1 | 0 |
| Dblog | module | 1 | 0 |
| Domain | module | 1 | 0 |
| Molom | module | 1 | 0 |
| Overlay | module | 1 | 0 |
| System | module | 1 | 0 |
| Field_group | module | 1 | 1 |
| Pathauto | module | 1 | 1 |
| I18n | module | 1 | 10 |
| I18n_string | module | 1 | 10 |
| Views | module | 1 | 10 |
| Rules | module | 1 | 20 |
| Admin_menu | module | 1 | 100 |
+ ---------------------------- + -------- +

You can find all the core Hooks in Drupal on this page, which may be very useful to you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.