• Avail guidance to develop Drupal modules & Drupal themes
  • Share and get review of your code
  • Get Access to free CodeBooks and ThemeBooks
  • Drupal 5, 6 and 7 covered

About bhavinhjoshi

Drupal module hooks: install file

Printer-friendly versionSend to a DeveloperPDF version
2
0

When Developing a custom module for Drupal, we need to use Drupal APIs and we need to make use of Drupal hooks. There are many Drupal hooks available and different hooks go in different files.

In this section we will learn about all those required hooks which should be written when developing a custom Drupal module.

First we will look at the hooks which are written in .install file.

I'd like to make a note here that don't mistaken the .module as the Drupal module. A Drupal module is consist of one or more .module file, one or more .info file and optionally, one or more .install file.

So, first we look at the hooks in .install file.

hook_install()

  • Drupal 5.x - Table structure and other items like vocabulary and its terms to be used by the module.
  • Drpal 6.x - drupal_install_schema() i.e.

hook_uninstall()

  • Drupal 5 - SQL query to remove the table structure, vocabulary, terms, if any.
  • Drupal 6 - drupal_unsintall_schema()

hook_update_N()*

  • Drupal 5, 6, 7 - Alter query, update query (in case, you are writing a custom module), all the things that you want to alter
  • For Drupal version 6 and 7, this function/hook takes one optional parameter called $sandbox (though, you are free to name it anything), which ensures that, for long update tasks, there is no php time outs and all the update runs successfully.

hook_schema()**

  • Drupal 6, 7 - Table definition/structure in associative array format, creating/setting vocabulary/terms/variable and every thing else you wanna place before you use the module

*the N indicates an unique number within the install file. Which may indicate the version number of the module i.e.6100, where 6 is the Drupal version and 1.0.0 (100) is module version

**This hook is introduced in 6.x version of Drupal

Syndicate content

Sitestats

Recent comments

rss-top-right.png
toolbar powered by www.iconcy.com