You are here

function hook_install in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Extension/module.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 when a module is installed. 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 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()

\Drupal\Core\Extension\ModuleHandler::install()

hook_uninstall()

hook_modules_installed()

Related topics

27 functions implement hook_install()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

block_install in core/modules/block/block.install
Implements hook_install().
comment_install in core/modules/comment/comment.install
Implements hook_install().
contact_storage_test_install in core/modules/contact/tests/modules/contact_storage_test/contact_storage_test.install
Implements hook_install().
content_translation_install in core/modules/content_translation/content_translation.install
Implements hook_install().
entity_test_install in core/modules/system/tests/modules/entity_test/entity_test.install
Implements hook_install().

... See full list

3 invocations of hook_install()
ModuleInstaller::install in core/lib/Drupal/Core/Extension/ModuleInstaller.php
Installs a given list of modules.
NormalizerTestBase::setUp in core/modules/serialization/src/Tests/NormalizerTestBase.php
RestLinkManagerTest::testRestLinkManagers in core/modules/rest/src/Tests/RestLinkManagerTest.php
Tests that type hooks work as expected.

File

core/lib/Drupal/Core/Extension/module.api.php, line 224
Hooks related to module and update systems.

Code

function hook_install() {

  // Create the styles directory and ensure it's writable.
  $directory = file_default_scheme() . '://styles';
  $mode = isset($GLOBALS['install_state']['mode']) ? $GLOBALS['install_state']['mode'] : NULL;
  file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS, $mode);
}