From 99e0777322bd12b5b71cd4ac87b1d94fe0a05940 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 3 Jun 2015 15:54:37 +0100 Subject: [PATCH] Issue #2475715 by stefan.r, tstoeckler: Module uninstall form does not validate correctly and breaks the confirmation form after 60 seconds --- .../modules/system/src/Form/ModulesUninstallConfirmForm.php | 1 + core/modules/system/src/Form/ModulesUninstallForm.php | 6 ++++-- core/modules/system/src/Tests/Module/UninstallTest.php | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/core/modules/system/src/Form/ModulesUninstallConfirmForm.php b/core/modules/system/src/Form/ModulesUninstallConfirmForm.php index 5ee4adbe032..0208e7c495f 100644 --- a/core/modules/system/src/Form/ModulesUninstallConfirmForm.php +++ b/core/modules/system/src/Form/ModulesUninstallConfirmForm.php @@ -135,6 +135,7 @@ class ModulesUninstallConfirmForm extends ConfirmFormBase { // Prevent this page from showing when the module list is empty. if (empty($this->modules)) { + drupal_set_message($this->t('The selected modules could not be uninstalled, either due to a website problem or due to the uninstall confirmation form timing out. Please try again.'), 'error'); return $this->redirect('system.modules_uninstall'); } diff --git a/core/modules/system/src/Form/ModulesUninstallForm.php b/core/modules/system/src/Form/ModulesUninstallForm.php index 153e2caf8eb..f72fa433025 100644 --- a/core/modules/system/src/Form/ModulesUninstallForm.php +++ b/core/modules/system/src/Form/ModulesUninstallForm.php @@ -171,7 +171,7 @@ class ModulesUninstallForm extends FormBase { public function validateForm(array &$form, FormStateInterface $form_state) { // Form submitted, but no modules selected. if (!array_filter($form_state->getValue('uninstall'))) { - drupal_set_message($this->t('No modules selected.'), 'error'); + $form_state->setErrorByName('uninstall', $this->t('No modules selected.')); $form_state->setRedirect('system.modules_uninstall'); } } @@ -184,7 +184,9 @@ class ModulesUninstallForm extends FormBase { $modules = $form_state->getValue('uninstall'); $uninstall = array_keys(array_filter($modules)); $account = $this->currentUser()->id(); - $this->keyValueExpirable->setWithExpire($account, $uninstall, 60); + // Store the values for 6 hours. This expiration time is also used in + // the form cache. + $this->keyValueExpirable->setWithExpire($account, $uninstall, 6*60*60); // Redirect to the confirm form. $form_state->setRedirect('system.modules_uninstall_confirm'); diff --git a/core/modules/system/src/Tests/Module/UninstallTest.php b/core/modules/system/src/Tests/Module/UninstallTest.php index c7eb051c385..e43a674e125 100644 --- a/core/modules/system/src/Tests/Module/UninstallTest.php +++ b/core/modules/system/src/Tests/Module/UninstallTest.php @@ -106,6 +106,10 @@ class UninstallTest extends WebTestBase { // Make sure our unique cache entry is gone. $cached = \Drupal::cache()->get('uninstall_test'); $this->assertFalse($cached, 'Cache entry not found'); + // Make sure we get an error message when we try to confirm uninstallation + // of an empty list of modules. + $this->drupalGet('admin/modules/uninstall/confirm'); + $this->assertText(t('The selected modules could not be uninstalled, either due to a website problem or due to the uninstall confirmation form timing out. Please try again.'), 'Module uninstall confirmation form displays error message'); // Make sure confirmation page is accessible only during uninstall process. $this->drupalGet('admin/modules/uninstall/confirm');