diff --git a/core/lib/Drupal/Core/Entity/Form/DeleteMultipleForm.php b/core/lib/Drupal/Core/Entity/Form/DeleteMultipleForm.php index cfdcf27430..f4ffb8366c 100644 --- a/core/lib/Drupal/Core/Entity/Form/DeleteMultipleForm.php +++ b/core/lib/Drupal/Core/Entity/Form/DeleteMultipleForm.php @@ -257,10 +257,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { if ($delete_entities) { $storage->delete($delete_entities); - $message = $this->formatPlural(count($delete_entities), 'Deleted @count @item.', 'Deleted @count @items.', [ - '@item' => $this->entityType->getSingularLabel(), - '@items' => $this->entityType->getPluralLabel(), - ]); + $message = $this->getDeletedMessage(count($delete_entities)); $this->logger('content')->notice($message); } @@ -277,28 +274,57 @@ public function submitForm(array &$form, FormStateInterface $form_state) { } if ($count) { $total_count += $count; - $message = $this->formatPlural($count, 'Deleted @count @item translation.', 'Deleted @count @items translations.', [ - '@item' => $this->entityType->getSingularLabel(), - '@items' => $this->entityType->getPluralLabel(), - ]); - $this->logger('content')->notice($message); + $this->logger('content')->notice($this->getDeletedTranslationMessage($count)); } } if ($total_count) { - $this->messenger->addStatus($this->formatPlural($total_count, 'Deleted @count @item.', 'Deleted @count @items.', [ - '@item' => $this->entityType->getSingularLabel(), - '@items' => $this->entityType->getPluralLabel(), - ])); + $this->messenger->addStatus($this->getDeletedMessage($total_count)); } if ($inaccessible_entities) { - $this->messenger->addWarning($this->formatPlural(count($inaccessible_entities), "@count @item has not been deleted because you don't have the necessary permissions.", "@count @items has not been deleted because you don't have the necessary permissions.", [ - '@item' => $this->entityType->getSingularLabel(), - '@items' => $this->entityType->getPluralLabel(), - ])); + $this->messenger->addWarning($this->getInaccessibleMessage(count($inaccessible_entities))); } $this->tempStore->delete($this->currentUser->id()); $form_state->setRedirectUrl($this->getCancelUrl()); } + /** + * Returns the message to show the user after a translation was deleted. + * + * @param int $count + * Count of deleted translations. + * + * @return \Drupal\Core\StringTranslation\TranslatableMarkup + * The translation deleted message. + */ + protected function getDeletedTranslationMessage($count) { + return $this->formatPlural($count, 'Deleted @count translation.', 'Deleted @count translations.'); + } + + /** + * Returns the message to show the user after an item was deleted. + * + * @param int $count + * Count of deleted translations. + * + * @return \Drupal\Core\StringTranslation\TranslatableMarkup + * The item deleted message. + */ + protected function getDeletedMessage($count) { + return $this->formatPlural($count, 'Deleted @count item.', 'Deleted @count items.'); + } + + /** + * Returns the message to show the user when an item has not been deleted. + * + * @param int $count + * Count of deleted translations. + * + * @return \Drupal\Core\StringTranslation\TranslatableMarkup + * The item inaccessible message. + */ + protected function getInaccessibleMessage($count) { + return $this->formatPlural($count, "@count item has not been deleted because you do not have the necessary permissions.", "@count items have not been deleted because you do not have the necessary permissions."); + } + } diff --git a/core/modules/comment/src/Form/ConfirmDeleteMultiple.php b/core/modules/comment/src/Form/ConfirmDeleteMultiple.php index ef1deac0fa..4dd68a12dc 100644 --- a/core/modules/comment/src/Form/ConfirmDeleteMultiple.php +++ b/core/modules/comment/src/Form/ConfirmDeleteMultiple.php @@ -26,4 +26,34 @@ public function getCancelUrl() { return new Url('comment.admin'); } + /** + * {@inheritdoc} + */ + protected function getDeletedTranslationMessage($count) { + return $this->formatPlural($count, 'Deleted @count @item translation.', 'Deleted @count @items translations.', [ + '@item' => $this->entityType->getSingularLabel(), + '@items' => $this->entityType->getPluralLabel(), + ]); + } + + /** + * {@inheritdoc} + */ + protected function getDeletedMessage($count) { + return $this->formatPlural($count, 'Deleted @count @item.', 'Deleted @count @items.', [ + '@item' => $this->entityType->getSingularLabel(), + '@items' => $this->entityType->getPluralLabel(), + ]); + } + + /** + * {@inheritdoc} + */ + protected function getInaccessibleMessage($count) { + return $this->formatPlural($count, "@count @item has not been deleted because you do not have the necessary permissions.", "@count @items have not been deleted because you do not have the necessary permissions.", [ + '@item' => $this->entityType->getSingularLabel(), + '@items' => $this->entityType->getPluralLabel(), + ]); + } + } diff --git a/core/modules/node/src/Form/DeleteMultiple.php b/core/modules/node/src/Form/DeleteMultiple.php index fa1f6076fd..92c0667ee4 100644 --- a/core/modules/node/src/Form/DeleteMultiple.php +++ b/core/modules/node/src/Form/DeleteMultiple.php @@ -19,4 +19,34 @@ public function getCancelUrl() { return new Url('system.admin_content'); } + /** + * {@inheritdoc} + */ + protected function getDeletedTranslationMessage($count) { + return $this->formatPlural($count, 'Deleted @count @item translation.', 'Deleted @count @items translations.', [ + '@item' => $this->entityType->getSingularLabel(), + '@items' => $this->entityType->getPluralLabel(), + ]); + } + + /** + * {@inheritdoc} + */ + protected function getDeletedMessage($count) { + return $this->formatPlural($count, 'Deleted @count @item.', 'Deleted @count @items.', [ + '@item' => $this->entityType->getSingularLabel(), + '@items' => $this->entityType->getPluralLabel(), + ]); + } + + /** + * {@inheritdoc} + */ + protected function getInaccessibleMessage($count) { + return $this->formatPlural($count, "@count @item has not been deleted because you do not have the necessary permissions.", "@count @items have not been deleted because you do not have the necessary permissions.", [ + '@item' => $this->entityType->getSingularLabel(), + '@items' => $this->entityType->getPluralLabel(), + ]); + } + } diff --git a/core/tests/Drupal/FunctionalTests/Entity/DeleteMultipleFormTest.php b/core/tests/Drupal/FunctionalTests/Entity/DeleteMultipleFormTest.php index 88568dbf83..45f88d680e 100644 --- a/core/tests/Drupal/FunctionalTests/Entity/DeleteMultipleFormTest.php +++ b/core/tests/Drupal/FunctionalTests/Entity/DeleteMultipleFormTest.php @@ -97,8 +97,8 @@ public function testTranslatableEntities() { $delete_button->click(); $assert = $this->assertSession(); $assert->addressEquals('/user/' . $this->account->id()); - $assert->responseContains('Deleted 6 test entity - revisions, data table, and published interface entities.'); - $assert->responseContains('1 test entity - revisions, data table, and published interface has not been deleted because you don\'t have the necessary permissions.'); + $assert->responseContains('Deleted 6 items.'); + $assert->responseContains('1 item has not been deleted because you do not have the necessary permissions.'); \Drupal::entityTypeManager()->getStorage('entity_test_mulrevpub')->resetCache(); $remaining_entities = EntityTestMulRevPub::loadMultiple([$entity1->id(), $entity2->id(), $entity3->id(), $entity4->id()]); @@ -146,8 +146,8 @@ public function testUntranslatableEntities() { $delete_button->click(); $assert = $this->assertSession(); $assert->addressEquals('/user/' . $this->account->id()); - $assert->responseContains('Deleted 2 test entity - revisions entities.'); - $assert->responseContains('2 test entity - revisions entities has not been deleted because you don\'t have the necessary permissions.'); + $assert->responseContains('Deleted 2 items.'); + $assert->responseContains('2 items have not been deleted because you do not have the necessary permissions.'); \Drupal::entityTypeManager()->getStorage('entity_test_mulrevpub')->resetCache(); $remaining_entities = EntityTestRev::loadMultiple([$entity1->id(), $entity2->id(), $entity3->id(), $entity4->id()]); diff --git a/core/tests/Drupal/KernelTests/Core/Action/DeleteActionTest.php b/core/tests/Drupal/KernelTests/Core/Action/DeleteActionTest.php index c164af16d6..e5a2bd95da 100644 --- a/core/tests/Drupal/KernelTests/Core/Action/DeleteActionTest.php +++ b/core/tests/Drupal/KernelTests/Core/Action/DeleteActionTest.php @@ -49,6 +49,12 @@ public function testGetDerivativeDefinitions() { 'action_label' => 'Delete', 'confirm_form_route_name' => 'entity.entity_test_mulrevpub.delete_multiple_form', ], + 'entity_test_rev' => [ + 'type' => 'entity_test_rev', + 'label' => 'Delete test entity - revisions', + 'action_label' => 'Delete', + 'confirm_form_route_name' => 'entity.entity_test_rev.delete_multiple_form', + ], ], $deriver->getDerivativeDefinitions([ 'action_label' => 'Delete', ]));