diff --git a/core/modules/node/src/Form/DeleteMultiple.php b/core/modules/node/src/Form/DeleteMultiple.php index 227d4ba..785f12e 100644 --- a/core/modules/node/src/Form/DeleteMultiple.php +++ b/core/modules/node/src/Form/DeleteMultiple.php @@ -96,9 +96,16 @@ public function getConfirmText() { * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { + + // Nothing to delete, makes cancel the only option. $this->nodeInfo = $this->tempStoreFactory->get('node_multiple_delete_confirm')->get(\Drupal::currentUser()->id()); if (empty($this->nodeInfo)) { - return new RedirectResponse($this->getCancelUrl()->setAbsolute()->toString()); + $node_temp_store->delete($current_user_id); + drupal_set_message('No nodes to delete.', 'error'); + $form = parent::buildForm($form, $form_state); + $form['description']['#markup'] = 'Press cancel to return.'; + unset($form['actions']['submit']); + return $form; } /** @var \Drupal\node\NodeInterface[] $nodes */ $nodes = $this->storage->loadMultiple(array_keys($this->nodeInfo)); diff --git a/core/modules/system/src/Form/ModulesUninstallConfirmForm.php b/core/modules/system/src/Form/ModulesUninstallConfirmForm.php index d2fff4c..37c3a66 100644 --- a/core/modules/system/src/Form/ModulesUninstallConfirmForm.php +++ b/core/modules/system/src/Form/ModulesUninstallConfirmForm.php @@ -134,7 +134,10 @@ public function buildForm(array $form, FormStateInterface $form_state) { // Cancel is the only option 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'); + $form = parent::buildForm($form, $form_state); + unset($form['actions']['submit']); + $form['description']['#markup'] = 'Press cancel to return.'; + return $form; } $data = system_rebuild_module_data(); diff --git a/core/modules/system/src/Form/ModulesUninstallForm.php b/core/modules/system/src/Form/ModulesUninstallForm.php index c74439e..c0ad743 100644 --- a/core/modules/system/src/Form/ModulesUninstallForm.php +++ b/core/modules/system/src/Form/ModulesUninstallForm.php @@ -172,7 +172,6 @@ public function validateForm(array &$form, FormStateInterface $form_state) { // Form submitted, but no modules selected. if (!array_filter($form_state->getValue('uninstall'))) { $form_state->setErrorByName('uninstall', $this->t('No modules selected.')); - $form_state->setRedirect('system.modules_uninstall'); } } diff --git a/core/modules/user/src/Form/UserMultipleCancelConfirm.php b/core/modules/user/src/Form/UserMultipleCancelConfirm.php index 27794e7..fecb0a1 100644 --- a/core/modules/user/src/Form/UserMultipleCancelConfirm.php +++ b/core/modules/user/src/Form/UserMultipleCancelConfirm.php @@ -152,13 +152,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { // Output a notice that user 1 cannot be canceled. if (isset($root)) { - $redirect = (count($accounts) == 1); - $message = $this->t('The user account %name cannot be canceled.', array('%name' => $root->label())); - drupal_set_message($message, $redirect ? 'error' : 'warning'); - // If only user 1 was selected, redirect to the overview. - if ($redirect) { - return $this->redirect('entity.user.collection'); - } + drupal_set_message($this->t('The user account %name cannot be canceled.', array('%name' => $root->label())), 'warning'); } $form['operation'] = array('#type' => 'hidden', '#value' => 'cancel'); diff --git a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php index 48a8ad8..5c0aec0 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php @@ -661,6 +661,30 @@ public function providerTestChildAccessInheritance() { return $data; } + + /* + * Tests FormInterface::buildForm() returning a Response object. + * + * @covers ::retrieveForm + * + * @expectedException \UnexpectedValueException + * @expectedExceptionMessage Form builder functions must return arrays + */ + public function testFormBuildForm() { + $form_id = 'test_form_id'; + $expected_form = $this->getMockBuilder('Symfony\Component\HttpFoundation\Response') + ->disableOriginalConstructor() + ->getMock(); + $expected_form->expects($this->never()) + ->method('prepare'); + + $form_arg = $this->getMockForm($form_id, $expected_form); + + // Do an initial build of the form and track the build ID. + $form_state = new FormState(); + $this->formBuilder->buildForm($form_arg, $form_state); + } + } class TestForm implements FormInterface {