diff --git a/core/lib/Drupal/Core/Update/Form/UpdateScriptSelectionForm.php b/core/lib/Drupal/Core/Update/Form/UpdateScriptSelectionForm.php new file mode 100644 index 0000000000000000000000000000000000000000..ce01146dff35d7c07d44a7e31f50ae834bb42620 --- /dev/null +++ b/core/lib/Drupal/Core/Update/Form/UpdateScriptSelectionForm.php @@ -0,0 +1,134 @@ +<?php + +/** + * @file + * Contains \Drupal\Core\Update\Form\UpdateScriptSelectionForm. + */ + +namespace Drupal\Core\Update\Form; + +use Drupal\Core\Form\FormBase; + +/** + * Provides the list of available database module updates. + */ +class UpdateScriptSelectionForm extends FormBase { + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'update_script_selection_form'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state) { + $count = 0; + $incompatible_count = 0; + $form['start'] = array( + '#tree' => TRUE, + '#type' => 'details', + '#collapsed' => TRUE, + ); + + // Ensure system.module's updates appear first. + $form['start']['system'] = array(); + + $updates = update_get_update_list(); + $starting_updates = array(); + $incompatible_updates_exist = FALSE; + foreach ($updates as $module => $update) { + if (!isset($update['start'])) { + $form['start'][$module] = array( + '#type' => 'item', + '#title' => $module . ' module', + '#markup' => $update['warning'], + '#prefix' => '<div class="messages messages--warning">', + '#suffix' => '</div>', + ); + $incompatible_updates_exist = TRUE; + continue; + } + if (!empty($update['pending'])) { + $starting_updates[$module] = $update['start']; + $form['start'][$module] = array( + '#type' => 'hidden', + '#value' => $update['start'], + ); + $form['start'][$module . '_updates'] = array( + '#theme' => 'item_list', + '#items' => $update['pending'], + '#title' => $module . ' module', + ); + } + if (isset($update['pending'])) { + $count = $count + count($update['pending']); + } + } + + // Find and label any incompatible updates. + foreach (update_resolve_dependencies($starting_updates) as $data) { + if (!$data['allowed']) { + $incompatible_updates_exist = TRUE; + $incompatible_count++; + $module_update_key = $data['module'] . '_updates'; + if (isset($form['start'][$module_update_key]['#items'][$data['number']])) { + $text = $data['missing_dependencies'] ? 'This update will been skipped due to the following missing dependencies: <em>' . implode(', ', $data['missing_dependencies']) . '</em>' : "This update will be skipped due to an error in the module's code."; + $form['start'][$module_update_key]['#items'][$data['number']] .= '<div class="warning">' . $text . '</div>'; + } + // Move the module containing this update to the top of the list. + $form['start'] = array($module_update_key => $form['start'][$module_update_key]) + $form['start']; + } + } + + // Warn the user if any updates were incompatible. + if ($incompatible_updates_exist) { + drupal_set_message('Some of the pending updates cannot be applied because their dependencies were not met.', 'warning'); + } + + if (empty($count)) { + drupal_set_message(t('No pending updates.')); + unset($form); + $form['links'] = array( + '#theme' => 'links', + '#links' => update_helpful_links(), + ); + + // No updates to run, so caches won't get flushed later. Clear them now. + update_flush_all_caches(); + } + else { + $form['help'] = array( + '#markup' => '<p>The version of Drupal you are updating from has been automatically detected.</p>', + '#weight' => -5, + ); + if ($incompatible_count) { + $form['start']['#title'] = format_plural( + $count, + '1 pending update (@number_applied to be applied, @number_incompatible skipped)', + '@count pending updates (@number_applied to be applied, @number_incompatible skipped)', + array('@number_applied' => $count - $incompatible_count, '@number_incompatible' => $incompatible_count) + ); + } + else { + $form['start']['#title'] = format_plural($count, '1 pending update', '@count pending updates'); + } + $form['actions'] = array('#type' => 'actions'); + $form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => 'Apply pending updates', + '#button_type' => 'primary', + ); + } + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + } + +} diff --git a/core/update.php b/core/update.php index f3f381be103f476c4d93f5f989e35debeca8ed02..add3646becc37262b2adecc4133b6dff07d6cf27 100644 --- a/core/update.php +++ b/core/update.php @@ -15,6 +15,7 @@ */ use Drupal\Core\DrupalKernel; +use Drupal\Core\Update\Form\UpdateScriptSelectionForm; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\DependencyInjection\Reference; @@ -53,7 +54,7 @@ function update_selection_page() { cache()->deleteAll(); drupal_set_title('Drupal database update'); - $elements = drupal_get_form('update_script_selection_form'); + $elements = \Drupal::formBuilder()->getForm('Drupal\Core\Update\Form\UpdateScriptSelectionForm'); $output = drupal_render($elements); update_task_list('select'); @@ -61,110 +62,6 @@ function update_selection_page() { return $output; } -/** - * Form constructor for the list of available database module updates. - */ -function update_script_selection_form($form, &$form_state) { - $count = 0; - $incompatible_count = 0; - $form['start'] = array( - '#tree' => TRUE, - '#type' => 'details', - '#collapsed' => TRUE, - ); - - // Ensure system.module's updates appear first. - $form['start']['system'] = array(); - - $updates = update_get_update_list(); - $starting_updates = array(); - $incompatible_updates_exist = FALSE; - foreach ($updates as $module => $update) { - if (!isset($update['start'])) { - $form['start'][$module] = array( - '#type' => 'item', - '#title' => $module . ' module', - '#markup' => $update['warning'], - '#prefix' => '<div class="messages messages--warning">', - '#suffix' => '</div>', - ); - $incompatible_updates_exist = TRUE; - continue; - } - if (!empty($update['pending'])) { - $starting_updates[$module] = $update['start']; - $form['start'][$module] = array( - '#type' => 'hidden', - '#value' => $update['start'], - ); - $form['start'][$module . '_updates'] = array( - '#theme' => 'item_list', - '#items' => $update['pending'], - '#title' => $module . ' module', - ); - } - if (isset($update['pending'])) { - $count = $count + count($update['pending']); - } - } - - // Find and label any incompatible updates. - foreach (update_resolve_dependencies($starting_updates) as $data) { - if (!$data['allowed']) { - $incompatible_updates_exist = TRUE; - $incompatible_count++; - $module_update_key = $data['module'] . '_updates'; - if (isset($form['start'][$module_update_key]['#items'][$data['number']])) { - $text = $data['missing_dependencies'] ? 'This update will been skipped due to the following missing dependencies: <em>' . implode(', ', $data['missing_dependencies']) . '</em>' : "This update will be skipped due to an error in the module's code."; - $form['start'][$module_update_key]['#items'][$data['number']] .= '<div class="warning">' . $text . '</div>'; - } - // Move the module containing this update to the top of the list. - $form['start'] = array($module_update_key => $form['start'][$module_update_key]) + $form['start']; - } - } - - // Warn the user if any updates were incompatible. - if ($incompatible_updates_exist) { - drupal_set_message('Some of the pending updates cannot be applied because their dependencies were not met.', 'warning'); - } - - if (empty($count)) { - drupal_set_message(t('No pending updates.')); - unset($form); - $form['links'] = array( - '#theme' => 'links', - '#links' => update_helpful_links(), - ); - - // No updates to run, so caches won't get flushed later. Clear them now. - update_flush_all_caches(); - } - else { - $form['help'] = array( - '#markup' => '<p>The version of Drupal you are updating from has been automatically detected.</p>', - '#weight' => -5, - ); - if ($incompatible_count) { - $form['start']['#title'] = format_plural( - $count, - '1 pending update (@number_applied to be applied, @number_incompatible skipped)', - '@count pending updates (@number_applied to be applied, @number_incompatible skipped)', - array('@number_applied' => $count - $incompatible_count, '@number_incompatible' => $incompatible_count) - ); - } - else { - $form['start']['#title'] = format_plural($count, '1 pending update', '@count pending updates'); - } - $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array( - '#type' => 'submit', - '#value' => 'Apply pending updates', - '#button_type' => 'primary', - ); - } - return $form; -} - /** * Provides links to the homepage and administration pages. */