diff --git a/migrate_upgrade.routing.yml b/migrate_upgrade.routing.yml index df710f4..d869df5 100644 --- a/migrate_upgrade.routing.yml +++ b/migrate_upgrade.routing.yml @@ -1,8 +1,7 @@ migrate_upgrade.upgrade: path: '/upgrade' defaults: - _form: '\Drupal\migrate_upgrade\Form\MigrateUpgradeForm' - _title: 'Upgrade' + _controller: '\Drupal\migrate_upgrade\Controller\MigrateController::handle' requirements: _permission: 'administer software updates' options: diff --git a/src/Controller/MigrateController.php b/src/Controller/MigrateController.php index b0d13d2..89087a1 100644 --- a/src/Controller/MigrateController.php +++ b/src/Controller/MigrateController.php @@ -1,4 +1,5 @@ bareHtmlPageRenderer = $bare_html_page_renderer; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('bare_html_page_renderer') + ); + } + + /** + * + */ + public function handle(Request $request) { + + $upgrade_state['interactive'] = TRUE; + $regions = []; + $regions['sidebar_first'] = $this->updateTasksList('settings'); + $output = $this->get_form('\Drupal\migrate_upgrade\Form\MigrateUpgradeForm', $upgrade_state); + $title = isset($output['#title']) ? $output['#title'] : $this->t('Drupal upgrade'); + return $this->bareHtmlPageRenderer->renderBarePage($output, $title, '', $regions); + } + + /** + * Builds and processes a form for the upgrade environment. + * + * Ensures that FormBuilder does not redirect after submitting a form, since the + * installer uses a custom step/flow logic via install_run_tasks(). + * + * @param string|array $form_id + * The form ID to build and process. + * @param array $upgrade_state + * The current state of the installation. + * + * @return array|null + * A render array containing the form to render, or NULL in case the form was + * successfully submitted. + * + * @throws \Drupal\Core\Installer\Exception\InstallerException + */ + function get_form($form_id, array &$upgrade_state) { + // Ensure the form will not redirect, since install_run_tasks() uses a custom + // redirection logic. + $form_state = (new FormState()) + ->addBuildInfo('args', [&$upgrade_state]) + ->disableRedirect(); + $form_builder = \Drupal::formBuilder(); + if ($upgrade_state['interactive']) { + $form = $form_builder->buildForm($form_id, $form_state); + // If the form submission was not successful, the form needs to be rendered, + // which means the task is not complete yet. + if (!$form_state->isExecuted()) { + $upgrade_state['form_executed'] = FALSE; + } + } + return $form; + } + + /** + * Provides the update task list render array. + * + * @param string $active + * The active task. + * Can be one of 'requirements', 'info', 'selection', 'run', 'results'. + * + * @return array + * A render array. + */ + protected function updateTasksList($active = NULL) { + // Default list of tasks. + $tasks = array( + 'overview' => $this->t('Overview'), + 'settings' => $this->t('Settings'), + 'review' => $this->t('Review updates'), + ); + + $task_list = array( + '#theme' => 'maintenance_task_list', + '#items' => $tasks, + '#active' => $active, + ); + return $task_list; + } + + /** * Sets a log filter and redirects to the log. */ public function showLog() { @@ -21,4 +126,5 @@ class MigrateController extends ControllerBase { $_SESSION['dblog_overview_filter']['type'] = ['migrate_upgrade' => 'migrate_upgrade']; return $this->redirect('dblog.overview'); } + }