Community Documentation

hook_install

5 install.php hook_install()
6 install.php hook_install()
7 system.api.php hook_install()
8 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.

Implementations of this hook are by convention declared in the module's .install file. The implementation can rely on the .module file being loaded. The 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, any time 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

▾ 112 functions implement hook_install()

actions_loop_test.install in modules/simpletest/tests/actions_loop_test.install
actions_loop_test_install in modules/simpletest/tests/actions_loop_test.install
Implements hook_install().
aggregator.install in modules/aggregator/aggregator.install
Install, update and uninstall functions for the aggregator module.
aggregator_uninstall in modules/aggregator/aggregator.install
Implements hook_uninstall().
block.install in modules/block/block.install
Install, update and uninstall functions for the block module.
block_install in modules/block/block.install
Implements hook_install().
blog.install in modules/blog/blog.install
Install, update and uninstall functions for the blog module.
blog_install in modules/blog/blog.install
Implements hook_install().
blog_uninstall in modules/blog/blog.install
Implements hook_uninstall().
book.install in modules/book/book.install
Install, update and uninstall functions for the book module.
book_install in modules/book/book.install
Implements hook_install().
book_uninstall in modules/book/book.install
Implements hook_uninstall().
color.install in modules/color/color.install
Install, update and uninstall functions for the color module.
comment.install in modules/comment/comment.install
Install, update and uninstall functions for the comment module.
comment_uninstall in modules/comment/comment.install
Implements hook_uninstall().
contact.install in modules/contact/contact.install
Install, update and uninstall functions for the contact module.
contact_install in modules/contact/contact.install
Implements hook_install().
contact_uninstall in modules/contact/contact.install
Implements hook_uninstall().
dashboard.install in modules/dashboard/dashboard.install
Install, update and uninstall functions for the dashboard module.
dashboard_uninstall in modules/dashboard/dashboard.install
Implements hook_uninstall().
database_test.install in modules/simpletest/tests/database_test.install
Install, update and uninstall functions for the database_test module.
dblog.install in modules/dblog/dblog.install
Install, update and uninstall functions for the dblog module.
dblog_uninstall in modules/dblog/dblog.install
Implements hook_uninstall().
DrupalUpdaterInterface::postInstall in includes/updater.inc
Actions to run after an install has occurred.
EnableDisableTestCase::assertSuccessfulDisableAndUninstall in modules/system/system.test
Disables and uninstalls a module and asserts that it was done correctly.
field.install in modules/field/field.install
Install, update and uninstall functions for the field module.
field_sql_storage.install in modules/field/modules/field_sql_storage/field_sql_storage.install
Install, update and uninstall functions for the field_sql_storage module.
field_test.install in modules/field/tests/field_test.install
Install, update and uninstall functions for the field_test module.
field_test_install in modules/field/tests/field_test.install
Implements hook_install().
file.install in modules/file/file.install
Install, update and uninstall functions for File module.
filter.install in modules/filter/filter.install
Install, update and uninstall functions for the filter module.
filter_install in modules/filter/filter.install
Implements hook_install().
forum.install in modules/forum/forum.install
Install, update and uninstall functions for the forum module.
forum_install in modules/forum/forum.install
Implements hook_install().
forum_uninstall in modules/forum/forum.install
Implements hook_uninstall().
hook_uninstall in modules/system/system.api.php
Remove any information that the module sets.
image.install in modules/image/image.install
Install, update and uninstall functions for the image module.
image_install in modules/image/image.install
Implements hook_install().
image_uninstall in modules/image/image.install
Implements hook_uninstall().
list.install in modules/field/modules/list/list.install
Install, update and uninstall functions for the list module.
locale.install in modules/locale/locale.install
Install, update and uninstall functions for the locale module.
locale_install in modules/locale/locale.install
Implements hook_install().
locale_uninstall in modules/locale/locale.install
Implements hook_uninstall().
menu.install in modules/menu/menu.install
Install, update and uninstall functions for the menu module.
menu_install in modules/menu/menu.install
Implements hook_install().
menu_uninstall in modules/menu/menu.install
Implements hook_uninstall().
minimal.install in profiles/minimal/minimal.install
minimal_install in profiles/minimal/minimal.install
Implements hook_install().
module_load_install in includes/module.inc
Load a module's installation hooks.
module_test.install in modules/simpletest/tests/module_test.install
Install, update and uninstall functions for the module_test module.
module_test_install in modules/simpletest/tests/module_test.install
Implements hook_install().
node.install in modules/node/node.install
Install, update and uninstall functions for the node module.
node_access_test.install in modules/node/tests/node_access_test.install
Install, update and uninstall functions for the node_access_test module.
node_install in modules/node/node.install
Implements hook_install().
number.install in modules/field/modules/number/number.install
Install, update and uninstall functions for the number module.
openid.install in modules/openid/openid.install
Install, update and uninstall functions for the openid module.
openid_test.install in modules/openid/tests/openid_test.install
Install, update and uninstall functions for the openid_test module.
openid_test_install in modules/openid/tests/openid_test.install
Implements hook_install().
overlay.install in modules/overlay/overlay.install
Install, update and uninstall functions for the overlay module.
php.install in modules/php/php.install
Install, update and uninstall functions for the php module.
poll.install in modules/poll/poll.install
Install, update and uninstall functions for the poll module.
profile.install in modules/profile/profile.install
Install, update and uninstall functions for the profile module.
profile_uninstall in modules/profile/profile.install
Implements hook_uninstall().
rdf.install in modules/rdf/rdf.install
Install, update and uninstall functions for the rdf module.
rdf_install in modules/rdf/rdf.install
Implements hook_install().
rdf_test.install in modules/rdf/tests/rdf_test.install
Install, update and uninstall functions for the rdf module.
rdf_test_install in modules/rdf/tests/rdf_test.install
Implements hook_install().
requirements1_test.install in modules/simpletest/tests/requirements1_test.install
search.install in modules/search/search.install
Install, update and uninstall functions for the search module.
search_uninstall in modules/search/search.install
Implements hook_uninstall().
shortcut.install in modules/shortcut/shortcut.install
Install, update and uninstall functions for the shortcut module.
shortcut_install in modules/shortcut/shortcut.install
Implements hook_install().
shortcut_uninstall in modules/shortcut/shortcut.install
Implements hook_uninstall().
simpletest.install in modules/simpletest/simpletest.install
Install, update and uninstall functions for the simpletest module.
simpletest_uninstall in modules/simpletest/simpletest.install
Implements hook_uninstall().
standard.install in profiles/standard/standard.install
standard_install in profiles/standard/standard.install
Implements hook_install().
statistics.install in modules/statistics/statistics.install
Install, update and uninstall functions for the statistics module.
statistics_uninstall in modules/statistics/statistics.install
Implements hook_uninstall().
syslog.install in modules/syslog/syslog.install
Install, update and uninstall functions for the syslog module.
syslog_uninstall in modules/syslog/syslog.install
Implements hook_uninstall().
system.install in modules/system/system.install
Install, update and uninstall functions for the system module.
system_install in modules/system/system.install
Implements hook_install().
system_modules_uninstall in modules/system/system.admin.inc
Builds a form of currently disabled modules.
taxonomy.install in modules/taxonomy/taxonomy.install
Install, update and uninstall functions for the taxonomy module.
TaxonomyVocabularyUnitTest::testUninstallReinstall in modules/taxonomy/taxonomy.test
Test uninstall and reinstall of the taxonomy module.
taxonomy_test.install in modules/simpletest/tests/taxonomy_test.install
Install, update and uninstall functions for the taxonomy_test module.
taxonomy_uninstall in modules/taxonomy/taxonomy.install
Implements hook_uninstall().
testing.install in profiles/testing/testing.install
testing_install in profiles/testing/testing.install
Implements hook_install().
text.install in modules/field/modules/text/text.install
Install, update and uninstall functions for the text module.
ThemeUpdater::postInstall in modules/system/system.updater.inc
Perform actions after installation.
theme_system_modules_uninstall in modules/system/system.admin.inc
Returns HTML for a table of currently disabled modules.
tracker.install in modules/tracker/tracker.install
tracker_uninstall in modules/tracker/tracker.install
Implements hook_uninstall().
trigger.install in modules/trigger/trigger.install
Install, update and uninstall functions for the trigger module.
trigger_install in modules/trigger/trigger.install
Implements hook_install().
Update manager: install in modules/update/update.manager.inc
Update manager for installing new code.
update.install in modules/update/update.install
Install, update and uninstall functions for the update module.
Updater::install in includes/updater.inc
Installs a Drupal project, returns a list of next actions.
Updater::postInstall in includes/updater.inc
Perform actions after installation.
update_authorize_run_install in modules/update/update.authorize.inc
Callback invoked by authorize.php to install a new project.
update_install in modules/update/update.install
Implements hook_install().
update_script_test.install in modules/simpletest/tests/update_script_test.install
Install, update and uninstall functions for the update_script_test module.
update_test_1.install in modules/simpletest/tests/update_test_1.install
Install, update and uninstall functions for the update_test_1 module.
update_test_2.install in modules/simpletest/tests/update_test_2.install
Install, update and uninstall functions for the update_test_2 module.
update_test_3.install in modules/simpletest/tests/update_test_3.install
Install, update and uninstall functions for the update_test_3 module.
update_uninstall in modules/update/update.install
Implements hook_uninstall().
url_alter_test.install in modules/simpletest/tests/url_alter_test.install
url_alter_test_install in modules/simpletest/tests/url_alter_test.install
Impelement hook_install().
user.install in modules/user/user.install
Install, update and uninstall functions for the user module.
user_install in modules/user/user.install
Implements hook_install().

File

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

Code

<?php
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();
}
?>

Comments

Availability of module's functions in its hook_install()

"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." It sounds like it, from that statement, that functions from the module you are enabling are available. We should maybe clarify that a bit more because in the drupal 6 version of this hook, they are not and you will get an undefined function error.

http://api.drupal.org/api/drupal/developer--hooks--install.php/function/...

Assumed knowledge

Note that this function needs to live in a .install file, as .module files will not be loaded during install/uninstall actions.

Login or register to post comments