Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
Move a few things around and add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
phenaproxima committed Jul 31, 2024
1 parent 4dbfdf7 commit 83734b2
Showing 1 changed file with 36 additions and 42 deletions.
78 changes: 36 additions & 42 deletions installer/starshot_installer.profile
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ use Symfony\Component\Process\ExecutableFinder;
function starshot_installer_install_tasks(): array {
return [
'starshot_installer_choose_template' => [
'run' => INSTALL_TASK_RUN_IF_REACHED,
'display_name' => t('Choose template'),
// Because the choice of template is currently hard-coded, this should
// not be presented to the user.
// 'display_name' => t('Choose template'),
],
'starshot_installer_apply_recipes' => [
'starshot_installer_apply_template' => [
'type' => 'batch',
'display_name' => t('Apply recipes'),
],
'starshot_installer_additional_recipes' => [
'run' => INSTALL_TASK_RUN_IF_REACHED,
'display_name' => t('Apply additional recipes'),
],
// 'starshot_installer_choose_add_on_recipes' => [
// We don't currently have the ability to present add-on recipes, so for
// now this task doesn't do anything and is hidden from users.
// @todo Fill this in after https://www.drupal.org/i/3450629 is fixed.
// 'display_name' => t('Choose add-ons'),
// ],
'starshot_installer_uninstall_myself' => [
// As a final task, this profile should uninstall itself.
],
Expand Down Expand Up @@ -100,27 +102,41 @@ function _starshot_installer_install_configure_form_submit(array &$form, FormSta
}

/**
* Runs a batch job that applies all of the Starshot recipes.
* Presents the user which a choice of which template should set up the site.
*
* @param $install_state
* @param array $install_state
* An array of information about the current installation state.
*
* @see starshot_installer_apply_template()
*/
function starshot_installer_choose_template(array &$install_state): void {
// For now, hard-code the choice to the main Starshot recipe. When more
// choices are available, this should present a form whose submit handler
// should set the `template` install parameter for
// starshot_installer_apply_template() to act upon.
$install_state['parameters']['template'] = Drupal::root() . '/recipes/starshot';
}

/**
* Runs a batch job that applies the template recipe.
*
* @param array $install_state
* An array of information about the current installation state.
*
* @return array
* The batch job definition.
*/
function starshot_installer_apply_recipes(&$install_state): array {
if (!empty($install_state['parameters']['template'])) {
$batch = new BatchBuilder();
$batch->setTitle(t('Applying recipes'));
function starshot_installer_apply_template(array &$install_state): array {
$batch = new BatchBuilder();
$batch->setTitle(t('Applying recipes'));

$recipe = Recipe::createFromDirectory(Drupal::root() . $install_state['parameters']['template']);
Drupal::classResolver(InputCollector::class)->prepare($recipe);
$recipe = Recipe::createFromDirectory($install_state['parameters']['template']);
Drupal::classResolver(InputCollector::class)->prepare($recipe);

foreach (RecipeRunner::toBatchOperations($recipe) as [$callback, $arguments]) {
$batch->addOperation($callback, $arguments);
}
return $batch->toArray();
foreach (RecipeRunner::toBatchOperations($recipe) as [$callback, $arguments]) {
$batch->addOperation($callback, $arguments);
}
return $batch->toArray();
}

/**
Expand All @@ -131,25 +147,3 @@ function starshot_installer_uninstall_myself(): void {
'starshot_installer',
]);
}

/**
* Sets up Starshot base recipe.
*
* @param $install_state
* An array of information about the current installation state.
*
* @see starshot_installer_apply_recipes()
*/
function starshot_installer_choose_template(&$install_state) {
$install_state['parameters']['template'] = '/recipes/starshot';
}

/**
* Gets additional recipes list.
*
* @param $install_state
* An array of information about the current installation state.
*/
function starshot_installer_additional_recipes(&$install_state) {
// @todo Get list once https://www.drupal.org/project/project_browser/issues/3450629 is fixed.
}

0 comments on commit 83734b2

Please sign in to comment.