Most common hooks that are used in drupal 6 and drupal 7

| | 2 min read
  • 1. hook_init()

    It gets called at the beginning of a page request (but after the modules and themes are loaded into memory) and it?s typically used to set global parameters that may be needed in the request. One thing to note about it is that it is not run on cached pages.

  • 2. hook_views_api()

    hook_views_api() is not a Drupal core hook but one from the Views module .It is used to register Views API information (including the necessary files for Views) usually for implementing hook_views_default_views().

  • 3.hook_form_alter()

    hook_form_BASE_FORM_ID_alter() and hook_form_FORM_ID_alter(), these hooks are used to alter the display of given forms on the site. If you want to add other Form API fields to an existing form.

  • 4. hook_help()

    hook_help() is used to provide documentation to a module right on the site where it gets implemented.

  • 5. hook_schema()

    hook_schema() is implemented in .install files in order to define database schemas for the module implementing it. When installing the module, Drupal automatically creates these tables according to this schema.

  • 6. hook_theme()

    A very popular one indeed - also in themes not just modules - hook_theme() is used to define and register various theme implementations needed by the module or theme.

  • 7. hook_install()

    hook_install() is another hook that gets implemented in a module?s .install file and gets called when the module is enabled for the first time or after it has been uninstalled. Additionally, it is called with a full bootstrap which means that all functions are available for it. Very powerful and useful.

  • 8. hook_permission()

    Drupal is very powerful when it comes to user management and the granularity with which you can administer permissions is impressive. Implementing hook_permission() allows a module to register its own custom permission that a user role must have in order to perform some actions.

  • 9. hook_uninstall()

    Sitting on the other side of hook_install(), hook_uninstall() is used to remove anything the module needs to remove when it gets uninstalled - apart from its entry in the systems table and the database tables it defines using hook_schema() as they get removed automatically.

  • 10. hook_menu()

    This hook enables modules to register paths in order to define how URL requests are handled. Paths may be registered for URL handling only, or they can register a link to be placed in a menu (usually the Navigation menu). A path and its associated information is commonly called a "menu router item". This hook is rarely called (for example, when modules are enabled), and its results are cached in the database.