Skip navigation
Help

hook_install

6 install.php hook_install()
7 system.api.php hook_install()

Perform setup tasks when the module is installed.

If the module implements hook_schema(), the database tables will be created before this hook is fired.

This hook will only be called the first time a module is enabled or after it is re-enabled after being uninstalled. The module's schema version will be set to the module's greatest numbered update hook. Because of this, anytime a hook_update_N() is added to the module, this function needs to be updated to reflect the current version of the database schema.

See the Schema API documentation at http://drupal.org/node/146843 for details on hook_schema and how database tables are defined.

Note that since this function is called from a full bootstrap, all functions (including those in modules enabled by the current page request) are available when this hook is called. Use cases could be displaying a user message, or calling a module function necessary for initial setup, etc.

Please be sure that anything added or modified in this function that can be removed during uninstall should be removed with hook_uninstall().

See also

hook_schema()

module_enable()

hook_enable()

hook_disable()

hook_uninstall()

hook_modules_installed()

Related topics

26 functions implement hook_install()

3 invocations of hook_install()

File

drupal/modules/system/system.api.php, line 3063
Hooks provided by Drupal core and the System module.

Code

function hook_install() {
  // Populate the default {node_access} record.
  db_insert('node_access')
    ->fields(array(
    'nid' => 0, 
    'gid' => 0, 
    'realm' => 'all', 
    'grant_view' => 1, 
    'grant_update' => 0, 
    'grant_delete' => 0,
  ))
    ->execute();
}