From 8b9dfcef25a387ce555df00c226265bf24d6cb66 Mon Sep 17 00:00:00 2001 From: xjm <xjm@65776.no-reply.drupal.org> Date: Mon, 27 Apr 2015 04:43:05 -0500 Subject: [PATCH] Issue #2400143 by geertvd, pcambra, koence, pjonckiere: Bulk form actions display action message in the confirmation form --- core/modules/action/src/Tests/BulkFormTest.php | 5 +++++ .../system/src/Plugin/views/field/BulkForm.php | 15 +++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/core/modules/action/src/Tests/BulkFormTest.php b/core/modules/action/src/Tests/BulkFormTest.php index f92329c7f6ae..88892c41d305 100644 --- a/core/modules/action/src/Tests/BulkFormTest.php +++ b/core/modules/action/src/Tests/BulkFormTest.php @@ -148,7 +148,12 @@ public function testBulkForm() { } $edit += array('action' => 'node_delete_action'); $this->drupalPostForm(NULL, $edit, t('Apply')); + // Make sure we don't show an action message while we are still on the + // confirmation page. + $errors = $this->xpath('//div[contains(@class, "messages--status")]'); + $this->assertFalse($errors, 'No action message shown.'); $this->drupalPostForm(NULL, array(), t('Delete')); + $this->assertText(t('Deleted 5 posts.')); // Check if we got redirected to the original page. $this->assertUrl('test_bulk_form'); } diff --git a/core/modules/system/src/Plugin/views/field/BulkForm.php b/core/modules/system/src/Plugin/views/field/BulkForm.php index b67bf8a349d7..6c72c6fd9ada 100644 --- a/core/modules/system/src/Plugin/views/field/BulkForm.php +++ b/core/modules/system/src/Plugin/views/field/BulkForm.php @@ -291,13 +291,16 @@ public function viewsFormSubmit(&$form, FormStateInterface $form_state) { ); $form_state->setRedirect($operation_definition['confirm_form_route_name'], array(), $options); } - - if ($count) { - drupal_set_message($this->formatPlural($count, '%action was applied to @count item.', '%action was applied to @count items.', array( - '%action' => $action->label(), - ))); + else { + // Don't display the message unless there are some elements affected and + // there is no confirmation form. + $count = count(array_filter($form_state->getValue($this->options['id']))); + if ($count) { + drupal_set_message($this->formatPlural($count, '%action was applied to @count item.', '%action was applied to @count items.', array( + '%action' => $action->label(), + ))); + } } - } } -- GitLab