Skip to content

Commit

Permalink
Adds new install step, which calls a new hook. (#751)
Browse files Browse the repository at this point in the history
* Adds new install step, which calls a new hook (hook_localgov_post_install), so modules can run tasks at the end of a site install.

* Code style.
  • Loading branch information
rupertj committed Aug 6, 2024
1 parent cd34148 commit bd1b3b9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
30 changes: 30 additions & 0 deletions localgov.api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* @file
* Hooks provided by the LocalGov install profile.
*/

/**
* @addtogroup hooks
* @{
*/

/**
* Run a task during the site installation process.
*
* This is intended for work that needs to happen when installing a localgov
* site, that can't happen in a module's hook_install(). This hook is invoked
* later in the install process, when everything bar the importing of
* translations is done.
*
* It can also be used to only run code during a site install, and not when a
* module is installed in an existing site.
*/
function hook_localgov_post_install(): void {
// Whatever your module needs to do goes here.
}

/**
* @} End of "addtogroup hooks".
*/
25 changes: 25 additions & 0 deletions localgov.profile
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,28 @@ function localgov_page_attachments(array &$attachments): void {
}
}
}

/**
* Implements hook_install_tasks().
*/
function localgov_install_tasks(array &$install_state): array {
return [
'localgov_post_install_task' => [
'display_name' => t('Localgov post install'),
'display' => TRUE,
],
];
}

/**
* This is an install step, added by localgov_install_tasks().
*
* We use this step to call a hook to allow other localgov modules to set things
* up as part of the site installation process that they can't do in their
* install hooks.
*/
function localgov_post_install_task(): void {
\Drupal::moduleHandler()->invokeAllWith('localgov_post_install', function (callable $hook, string $module) {
$hook();
});
}

0 comments on commit bd1b3b9

Please sign in to comment.