From 3d75726b80c7ef41b94b18d9fa9cc137e9838419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=C3=A9na=20Proxima?= Date: Wed, 31 Jul 2024 08:22:21 -0400 Subject: [PATCH] Move a few things around and add comments --- installer/starshot_installer.profile | 78 +++++++++++++--------------- 1 file changed, 36 insertions(+), 42 deletions(-) diff --git a/installer/starshot_installer.profile b/installer/starshot_installer.profile index 478a80b0..b089a9e4 100644 --- a/installer/starshot_installer.profile +++ b/installer/starshot_installer.profile @@ -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 tasks doesn't do anything and is invisible to 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. ], @@ -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(); } /** @@ -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. -}