diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php b/core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php new file mode 100644 index 0000000..590b80f --- /dev/null +++ b/core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php @@ -0,0 +1,17 @@ +t('Are you sure you want to delete the @entity-type %label?', array( + '@entity-type' => $this->getEntity()->getEntityType()->getLowercaseLabel(), + '%label' => $this->getEntity()->label(), + )); + } + + /** + * {@inheritdoc} + */ + public function getConfirmText() { + return $this->t('Delete'); + } + + /** + * Returns the message to display to the user after deleting the entity. + * + * @return string + * The translated string of the deletion message. + */ + protected function getDeletionMessage() { + $entity = $this->getEntity(); + return $this->t('The @entity-type %label has been deleted.', array( + '@entity-type' => $entity->getEntityType()->getLowercaseLabel(), + '%label' => $entity->label(), + )); + } + + /** + * {@inheritdoc} + */ + public function getCancelUrl() { + $entity = $this->getEntity(); + if ($entity->hasLinkTemplate('collection')) { + // If available, return the collection URL. + return $entity->urlInfo('collection'); + } + else { + // Otherwise fall back to the default link template. + return $entity->urlInfo(); + } + } + + /** + * Logs a message about the deleted entity. + */ + protected function logDeletionMessage() { + $entity = $this->getEntity(); + $this->logger($entity->getEntityType()->getProvider())->notice('The @entity-type %label has been deleted.', array( + '@entity-type' => $entity->getEntityType()->getLowercaseLabel(), + '%label' => $entity->label(), + )); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $this->getEntity()->delete(); + drupal_set_message($this->getDeletionMessage()); + $form_state->setRedirectUrl($this->getCancelUrl()); + $this->logDeletionMessage(); + } + +} diff --git a/core/modules/action/src/Form/ActionDeleteForm.php b/core/modules/action/src/Form/ActionDeleteForm.php index 93e47ab..9ac54af 100644 --- a/core/modules/action/src/Form/ActionDeleteForm.php +++ b/core/modules/action/src/Form/ActionDeleteForm.php @@ -7,28 +7,13 @@ namespace Drupal\action\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; -use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Url; /** * Builds a form to delete an action. */ -class ActionDeleteForm extends EntityConfirmFormBase { - - /** - * {@inheritdoc} - */ - public function getQuestion() { - return $this->t('Are you sure you want to delete the action %action?', array('%action' => $this->entity->label())); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return $this->t('Delete'); - } +class ActionDeleteForm extends EntityDeleteForm { /** * {@inheritdoc} @@ -37,16 +22,4 @@ public function getCancelUrl() { return new Url('entity.action.collection'); } - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); - - $this->logger('user')->notice('Deleted action %aid (%action)', array('%aid' => $this->entity->id(), '%action' => $this->entity->label())); - drupal_set_message($this->t('Action %action was deleted', array('%action' => $this->entity->label()))); - - $form_state->setRedirectUrl($this->getCancelUrl()); - } - } diff --git a/core/modules/action/src/Tests/ConfigurationTest.php b/core/modules/action/src/Tests/ConfigurationTest.php index 7f226dd..57b2525 100644 --- a/core/modules/action/src/Tests/ConfigurationTest.php +++ b/core/modules/action/src/Tests/ConfigurationTest.php @@ -81,7 +81,7 @@ function testActionConfiguration() { $this->assertResponse(200); // Make sure that the action was actually deleted. - $this->assertRaw(t('Action %action was deleted', array('%action' => $new_action_label)), 'Make sure that we get a delete confirmation message.'); + $this->assertRaw(t('The action %action has been deleted.', array('%action' => $new_action_label)), 'Make sure that we get a delete confirmation message.'); $this->drupalGet('admin/config/system/actions'); $this->assertResponse(200); $this->assertNoText($new_action_label, "Make sure the action label does not appear on the overview page after we've deleted the action."); diff --git a/core/modules/aggregator/src/Form/FeedDeleteForm.php b/core/modules/aggregator/src/Form/FeedDeleteForm.php index 2f31bb0..2acab06 100644 --- a/core/modules/aggregator/src/Form/FeedDeleteForm.php +++ b/core/modules/aggregator/src/Form/FeedDeleteForm.php @@ -7,21 +7,13 @@ namespace Drupal\aggregator\Form; -use Drupal\Core\Entity\ContentEntityConfirmFormBase; -use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Entity\ContentEntityDeleteForm; use Drupal\Core\Url; /** * Provides a form for deleting a feed. */ -class FeedDeleteForm extends ContentEntityConfirmFormBase { - - /** - * {@inheritdoc} - */ - public function getQuestion() { - return $this->t('Are you sure you want to delete the feed %feed?', array('%feed' => $this->entity->label())); - } +class FeedDeleteForm extends ContentEntityDeleteForm { /** * {@inheritdoc} @@ -33,18 +25,10 @@ public function getCancelUrl() { /** * {@inheritdoc} */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); - $this->logger('aggregator')->notice('Feed %feed deleted.', array('%feed' => $this->entity->label())); - drupal_set_message($this->t('The feed %feed has been deleted.', array('%feed' => $this->entity->label()))); - $form_state->setRedirect('aggregator.admin_overview'); + protected function getDeletionMessage() { + return $this->t('The feed %label has been deleted.', array( + '%label' => $this->entity->label(), + )); } } diff --git a/core/modules/block/src/Form/BlockDeleteForm.php b/core/modules/block/src/Form/BlockDeleteForm.php index d797cf0..b36eaeb 100644 --- a/core/modules/block/src/Form/BlockDeleteForm.php +++ b/core/modules/block/src/Form/BlockDeleteForm.php @@ -7,21 +7,13 @@ namespace Drupal\block\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; -use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Url; /** * Provides a deletion confirmation form for the block instance deletion form. */ -class BlockDeleteForm extends EntityConfirmFormBase { - - /** - * {@inheritdoc} - */ - public function getQuestion() { - return $this->t('Are you sure you want to delete the block %name?', array('%name' => $this->entity->label())); - } +class BlockDeleteForm extends EntityDeleteForm { /** * {@inheritdoc} @@ -30,20 +22,4 @@ public function getCancelUrl() { return new Url('block.admin_display'); } - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); - drupal_set_message($this->t('The block %name has been removed.', array('%name' => $this->entity->label()))); - $form_state->setRedirectUrl($this->getCancelUrl()); - } - } diff --git a/core/modules/block/src/Tests/BlockTest.php b/core/modules/block/src/Tests/BlockTest.php index 1092ea5..197a370 100644 --- a/core/modules/block/src/Tests/BlockTest.php +++ b/core/modules/block/src/Tests/BlockTest.php @@ -171,7 +171,7 @@ function testBlock() { $this->clickLink(t('Delete')); $this->assertRaw(t('Are you sure you want to delete the block %name?', array('%name' => $block['settings[label]']))); $this->drupalPostForm(NULL, array(), t('Delete')); - $this->assertRaw(t('The block %name has been removed.', array('%name' => $block['settings[label]']))); + $this->assertRaw(t('The block %name has been deleted.', array('%name' => $block['settings[label]']))); // Test deleting a block via "Configure block" link. $block = $this->drupalPlaceBlock('system_powered_by_block'); @@ -179,7 +179,7 @@ function testBlock() { $this->clickLink(t('Delete')); $this->assertRaw(t('Are you sure you want to delete the block %name?', array('%name' => $block->label()))); $this->drupalPostForm(NULL, array(), t('Delete')); - $this->assertRaw(t('The block %name has been removed.', array('%name' => $block->label()))); + $this->assertRaw(t('The block %name has been deleted.', array('%name' => $block->label()))); $this->assertUrl('admin'); $this->assertNoRaw($block->id()); } diff --git a/core/modules/block_content/src/Form/BlockContentDeleteForm.php b/core/modules/block_content/src/Form/BlockContentDeleteForm.php index 0778ee2..f834ae6 100644 --- a/core/modules/block_content/src/Form/BlockContentDeleteForm.php +++ b/core/modules/block_content/src/Form/BlockContentDeleteForm.php @@ -7,35 +7,13 @@ namespace Drupal\block_content\Form; -use Drupal\Core\Entity\ContentEntityConfirmFormBase; +use Drupal\Core\Entity\ContentEntityDeleteForm; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Url; /** * Provides a confirmation form for deleting a custom block entity. */ -class BlockContentDeleteForm extends ContentEntityConfirmFormBase { - - /** - * {@inheritdoc} - */ - public function getQuestion() { - return $this->t('Are you sure you want to delete %name?', array('%name' => $this->entity->label())); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return new Url('block.admin_display'); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return $this->t('Delete'); - } +class BlockContentDeleteForm extends ContentEntityDeleteForm { /** * {@inheritdoc} @@ -51,14 +29,4 @@ public function buildForm(array $form, FormStateInterface $form_state) { return parent::buildForm($form, $form_state); } - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); - drupal_set_message($this->t('Custom block %label has been deleted.', array('%label' => $this->entity->label()))); - $this->logger('block_content')->notice('Custom block %label has been deleted.', array('%label' => $this->entity->label())); - $form_state->setRedirectUrl($this->entity->urlInfo('collection')); - } - } diff --git a/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php b/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php index 9b07b96..a9ec5d9 100644 --- a/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php +++ b/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php @@ -7,7 +7,7 @@ namespace Drupal\block_content\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; @@ -16,7 +16,7 @@ /** * Provides a confirmation form for deleting a custom block type entity. */ -class BlockContentTypeDeleteForm extends EntityConfirmFormBase { +class BlockContentTypeDeleteForm extends EntityDeleteForm { /** * The query factory to create entity queries. @@ -47,27 +47,6 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public function getQuestion() { - return $this->t('Are you sure you want to delete %label?', array('%label' => $this->entity->label())); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ public function buildForm(array $form, FormStateInterface $form_state) { $blocks = $this->queryFactory->get('block_content')->condition('type', $this->entity->id())->execute(); if (!empty($blocks)) { @@ -80,14 +59,4 @@ public function buildForm(array $form, FormStateInterface $form_state) { } } - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); - drupal_set_message(t('Custom block type %label has been deleted.', array('%label' => $this->entity->label()))); - $this->logger('block_content')->notice('Custom block type %label has been deleted.', array('%label' => $this->entity->label())); - $form_state->setRedirectUrl($this->getCancelUrl()); - } - } diff --git a/core/modules/block_content/src/Tests/BlockContentCreationTest.php b/core/modules/block_content/src/Tests/BlockContentCreationTest.php index 400ad50..e5a5ead 100644 --- a/core/modules/block_content/src/Tests/BlockContentCreationTest.php +++ b/core/modules/block_content/src/Tests/BlockContentCreationTest.php @@ -187,7 +187,7 @@ public function testBlockDelete() { $this->assertText(\Drupal::translation()->formatPlural(1, 'This will also remove 1 placed block instance.', 'This will also remove @count placed block instance.')); $this->drupalPostForm(NULL, array(), 'Delete'); - $this->assertRaw(t('Custom block %name has been deleted.', array('%name' => $edit['info[0][value]']))); + $this->assertRaw(t('The custom block %name has been deleted.', array('%name' => $edit['info[0][value]']))); // Create another block and force the plugin cache to flush. $edit2 = array(); diff --git a/core/modules/block_content/src/Tests/BlockContentListTest.php b/core/modules/block_content/src/Tests/BlockContentListTest.php index c644286..57c9d27 100644 --- a/core/modules/block_content/src/Tests/BlockContentListTest.php +++ b/core/modules/block_content/src/Tests/BlockContentListTest.php @@ -99,7 +99,7 @@ public function testListing() { $delete_text = t('Delete'); $this->clickLink($delete_text); $this->assertResponse(200); - $this->assertTitle(strip_tags(t('Are you sure you want to delete %label?', array('%label' => $new_label)) . ' | Drupal')); + $this->assertTitle(strip_tags(t('Are you sure you want to delete the custom block %label?', array('%label' => $new_label)) . ' | Drupal')); $this->drupalPostForm(NULL, array(), $delete_text); // Verify that the text of the label and machine name does not appear in diff --git a/core/modules/block_content/src/Tests/BlockContentTypeTest.php b/core/modules/block_content/src/Tests/BlockContentTypeTest.php index d59a25d..a45cd2f 100644 --- a/core/modules/block_content/src/Tests/BlockContentTypeTest.php +++ b/core/modules/block_content/src/Tests/BlockContentTypeTest.php @@ -126,7 +126,7 @@ public function testBlockContentTypeDeletion() { // Attempt to delete the block type, which should now be allowed. $this->drupalGet('admin/structure/block/block-content/manage/' . $type->id() . '/delete'); $this->assertRaw( - t('Are you sure you want to delete %type?', array('%type' => $type->id())), + t('Are you sure you want to delete the custom block type %type?', array('%type' => $type->id())), 'The block type is available for deletion.' ); $this->assertText(t('This action cannot be undone.'), 'The custom block type deletion confirmation form is available.'); diff --git a/core/modules/block_content/src/Tests/PageEditTest.php b/core/modules/block_content/src/Tests/PageEditTest.php index 3577547..ef56ad3 100644 --- a/core/modules/block_content/src/Tests/PageEditTest.php +++ b/core/modules/block_content/src/Tests/PageEditTest.php @@ -61,7 +61,7 @@ public function testPageEdit() { // Test deleting the block. $this->drupalGet("block/" . $revised_block->id()); $this->clickLink(t('Delete')); - $this->assertText(format_string('Are you sure you want to delete !label?', array('!label' => $revised_block->label()))); + $this->assertText(format_string('Are you sure you want to delete the custom block !label?', array('!label' => $revised_block->label()))); } } diff --git a/core/modules/comment/src/Form/CommentTypeDeleteForm.php b/core/modules/comment/src/Form/CommentTypeDeleteForm.php index 6fe26d4..9a859e8 100644 --- a/core/modules/comment/src/Form/CommentTypeDeleteForm.php +++ b/core/modules/comment/src/Form/CommentTypeDeleteForm.php @@ -8,7 +8,7 @@ namespace Drupal\comment\Form; use Drupal\comment\CommentManagerInterface; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Entity\EntityManager; use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Form\FormStateInterface; @@ -20,7 +20,7 @@ /** * Provides a confirmation form for deleting a comment type entity. */ -class CommentTypeDeleteForm extends EntityConfirmFormBase { +class CommentTypeDeleteForm extends EntityDeleteForm { /** * The query factory to create entity queries. @@ -91,27 +91,6 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public function getQuestion() { - return $this->t('Are you sure you want to delete %label?', array('%label' => $this->entity->label())); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ public function buildForm(array $form, FormStateInterface $form_state) { $comments = $this->queryFactory->get('comment')->condition('comment_type', $this->entity->id())->execute(); $entity_type = $this->entity->getTargetEntityTypeId(); @@ -138,14 +117,4 @@ public function buildForm(array $form, FormStateInterface $form_state) { } } - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); - $form_state->setRedirectUrl($this->entity->urlInfo('collection')); - drupal_set_message($this->t('Comment type %label has been deleted.', array('%label' => $this->entity->label()))); - $this->logger->notice('comment type %label has been deleted.', array('%label' => $this->entity->label())); - } - } diff --git a/core/modules/comment/src/Form/DeleteForm.php b/core/modules/comment/src/Form/DeleteForm.php index 0bb5720..4e995bb 100644 --- a/core/modules/comment/src/Form/DeleteForm.php +++ b/core/modules/comment/src/Form/DeleteForm.php @@ -7,20 +7,13 @@ namespace Drupal\comment\Form; -use Drupal\Core\Entity\ContentEntityConfirmFormBase; +use Drupal\Core\Entity\ContentEntityDeleteForm; use Drupal\Core\Form\FormStateInterface; /** * Provides the comment delete confirmation form. */ -class DeleteForm extends ContentEntityConfirmFormBase { - - /** - * {@inheritdoc} - */ - public function getQuestion() { - return $this->t('Are you sure you want to delete the comment %title?', array('%title' => $this->entity->subject->value)); - } +class DeleteForm extends ContentEntityDeleteForm { /** * {@inheritdoc} @@ -40,20 +33,17 @@ public function getDescription() { /** * {@inheritdoc} */ - public function getConfirmText() { - return $this->t('Delete'); + protected function getDeletionMessage() { + return $this->t('The comment and all its replies have been deleted.'); } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - // Delete the comment and its replies. - $this->entity->delete(); - drupal_set_message($this->t('The comment and all its replies have been deleted.')); + parent::submitForm($form, $form_state); + $this->logger('content')->notice('Deleted comment @cid and its replies.', array('@cid' => $this->entity->id())); - - $form_state->setRedirectUrl($this->getCancelUrl()); } } diff --git a/core/modules/comment/src/Tests/CommentTypeTest.php b/core/modules/comment/src/Tests/CommentTypeTest.php index 060d69d..2a43eec 100644 --- a/core/modules/comment/src/Tests/CommentTypeTest.php +++ b/core/modules/comment/src/Tests/CommentTypeTest.php @@ -169,7 +169,7 @@ public function testCommentTypeDeletion() { // Attempt to delete the comment type, which should now be allowed. $this->drupalGet('admin/structure/comment/manage/' . $type->id() . '/delete'); $this->assertRaw( - t('Are you sure you want to delete %type?', array('%type' => $type->id())), + t('Are you sure you want to delete the comment type %type?', array('%type' => $type->id())), 'The comment type is available for deletion.' ); $this->assertText(t('This action cannot be undone.'), 'The comment type deletion confirmation form is available.'); @@ -186,7 +186,7 @@ public function testCommentTypeDeletion() { // Delete the comment type. $this->drupalPostForm('admin/structure/comment/manage/' . $type->id() . '/delete', array(), t('Delete')); $this->assertNull(CommentType::load($type->id()), 'Comment type deleted.'); - $this->assertRaw(t('Comment type %label has been deleted.', array('%label' => $type->label()))); + $this->assertRaw(t('The comment type %label has been deleted.', array('%label' => $type->label()))); } } diff --git a/core/modules/config/src/Tests/ConfigEntityListTest.php b/core/modules/config/src/Tests/ConfigEntityListTest.php index c578ff2..3decafc 100644 --- a/core/modules/config/src/Tests/ConfigEntityListTest.php +++ b/core/modules/config/src/Tests/ConfigEntityListTest.php @@ -214,7 +214,7 @@ function testListUI() { $this->assertLinkByHref('admin/structure/config_test/manage/albatross/delete'); $this->clickLink('Delete', 1); $this->assertResponse(200); - $this->assertTitle('Are you sure you want to delete Albatross | Drupal'); + $this->assertTitle('Are you sure you want to delete the test configuration Albatross? | Drupal'); $this->drupalPostForm(NULL, array(), t('Delete')); // Verify that the text of the label and machine name does not appear in @@ -225,7 +225,7 @@ function testListUI() { // Delete the original entity using the operations link. $this->clickLink('Delete'); $this->assertResponse(200); - $this->assertTitle('Are you sure you want to delete Default | Drupal'); + $this->assertTitle('Are you sure you want to delete the test configuration Default? | Drupal'); $this->drupalPostForm(NULL, array(), t('Delete')); // Verify that the text of the label and machine name does not appear in diff --git a/core/modules/config/src/Tests/ConfigEntityTest.php b/core/modules/config/src/Tests/ConfigEntityTest.php index 2bf47f5..7cf16e6 100644 --- a/core/modules/config/src/Tests/ConfigEntityTest.php +++ b/core/modules/config/src/Tests/ConfigEntityTest.php @@ -241,7 +241,7 @@ function testCRUDUI() { $label3 = $this->randomMachineName(); $message_insert = format_string('%label configuration has been created.', array('%label' => $label1)); $message_update = format_string('%label configuration has been updated.', array('%label' => $label2)); - $message_delete = format_string('%label configuration has been deleted.', array('%label' => $label2)); + $message_delete = format_string('The test configuration %label has been deleted.', array('%label' => $label2)); // Create a configuration entity. $edit = array( diff --git a/core/modules/config/tests/config_test/src/Entity/ConfigTest.php b/core/modules/config/tests/config_test/src/Entity/ConfigTest.php index e27fc16..4357597 100644 --- a/core/modules/config/tests/config_test/src/Entity/ConfigTest.php +++ b/core/modules/config/tests/config_test/src/Entity/ConfigTest.php @@ -23,7 +23,7 @@ * "list_builder" = "Drupal\config_test\ConfigTestListBuilder", * "form" = { * "default" = "Drupal\config_test\ConfigTestForm", - * "delete" = "Drupal\config_test\Form\ConfigTestDeleteForm" + * "delete" = "Drupal\Core\Entity\EntityDeleteForm" * }, * "access" = "Drupal\config_test\ConfigTestAccessControlHandler" * }, diff --git a/core/modules/config/tests/config_test/src/Form/ConfigTestDeleteForm.php b/core/modules/config/tests/config_test/src/Form/ConfigTestDeleteForm.php deleted file mode 100644 index 05d9dc2..0000000 --- a/core/modules/config/tests/config_test/src/Form/ConfigTestDeleteForm.php +++ /dev/null @@ -1,49 +0,0 @@ - $this->entity->label())); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return t('Delete'); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); - drupal_set_message(String::format('%label configuration has been deleted.', array('%label' => $this->entity->label()))); - $form_state->setRedirectUrl($this->getCancelUrl()); - } - -} diff --git a/core/modules/contact/src/Entity/ContactForm.php b/core/modules/contact/src/Entity/ContactForm.php index febc536..d4be3de 100644 --- a/core/modules/contact/src/Entity/ContactForm.php +++ b/core/modules/contact/src/Entity/ContactForm.php @@ -23,7 +23,7 @@ * "form" = { * "add" = "Drupal\contact\ContactFormEditForm", * "edit" = "Drupal\contact\ContactFormEditForm", - * "delete" = "Drupal\contact\Form\ContactFormDeleteForm" + * "delete" = "Drupal\Core\Entity\EntityDeleteForm" * } * }, * config_prefix = "form", diff --git a/core/modules/contact/src/Form/ContactFormDeleteForm.php b/core/modules/contact/src/Form/ContactFormDeleteForm.php deleted file mode 100644 index 1333305..0000000 --- a/core/modules/contact/src/Form/ContactFormDeleteForm.php +++ /dev/null @@ -1,50 +0,0 @@ -t('Are you sure you want to delete %name?', array('%name' => $this->entity->label())); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); - drupal_set_message($this->t('Contact form %label has been deleted.', array('%label' => $this->entity->label()))); - $this->logger('contact')->notice('Contact form %label has been deleted.', array('%label' => $this->entity->label())); - $form_state->setRedirectUrl($this->getCancelUrl()); - } - -} diff --git a/core/modules/contact/src/Tests/ContactSitewideTest.php b/core/modules/contact/src/Tests/ContactSitewideTest.php index 4757a45..e399798 100644 --- a/core/modules/contact/src/Tests/ContactSitewideTest.php +++ b/core/modules/contact/src/Tests/ContactSitewideTest.php @@ -414,7 +414,7 @@ function deleteContactForms() { } else { $this->drupalPostForm("admin/structure/contact/manage/$id/delete", array(), t('Delete')); - $this->assertRaw(t('Contact form %label has been deleted.', array('%label' => $contact_form->label()))); + $this->assertRaw(t('The contact form %label has been deleted.', array('%label' => $contact_form->label()))); $this->assertFalse(ContactForm::load($id), format_string('Form %contact_form not found', array('%contact_form' => $contact_form->label()))); } } diff --git a/core/modules/field_ui/src/Form/EntityDisplayModeDeleteForm.php b/core/modules/field_ui/src/Form/EntityDisplayModeDeleteForm.php index f50dbe6..f244163 100644 --- a/core/modules/field_ui/src/Form/EntityDisplayModeDeleteForm.php +++ b/core/modules/field_ui/src/Form/EntityDisplayModeDeleteForm.php @@ -7,28 +7,12 @@ namespace Drupal\field_ui\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; -use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Entity\EntityDeleteForm; /** * Provides the delete form for entity display modes. */ -class EntityDisplayModeDeleteForm extends EntityConfirmFormBase { - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } - - /** - * {@inheritdoc} - */ - public function getQuestion() { - $entity_type = $this->entity->getEntityType(); - return t('Are you sure you want to delete the %label @entity-type?', array('%label' => $this->entity->label(), '@entity-type' => $entity_type->getLowercaseLabel())); - } +class EntityDisplayModeDeleteForm extends EntityDeleteForm { /** * {@inheritdoc} @@ -38,22 +22,4 @@ public function getDescription() { return t('Deleting a @entity-type will cause any output still requesting to use that @entity-type to use the default display settings.', array('@entity-type' => $entity_type->getLowercaseLabel())); } - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return t('Delete'); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $entity_type = $this->entity->getEntityType(); - drupal_set_message(t('Deleted the %label @entity-type.', array('%label' => $this->entity->label(), '@entity-type' => strtolower($entity_type->getLabel())))); - $this->entity->delete(); - \Drupal::entityManager()->clearCachedFieldDefinitions(); - $form_state->setRedirectUrl($this->getCancelUrl()); - } - } diff --git a/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php b/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php index b1ddb05..4afe0e3 100644 --- a/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php +++ b/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php @@ -7,7 +7,7 @@ namespace Drupal\field_ui\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\field_ui\FieldUI; @@ -16,7 +16,7 @@ /** * Provides a form for removing a field from a bundle. */ -class FieldConfigDeleteForm extends EntityConfirmFormBase { +class FieldConfigDeleteForm extends EntityDeleteForm { /** * The entity manager. @@ -47,20 +47,6 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public function getQuestion() { - return $this->t('Are you sure you want to delete the field %field?', array('%field' => $this->entity->getLabel())); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ public function getCancelUrl() { return FieldUI::getOverviewRouteInfo($this->entity->entity_type, $this->entity->bundle); } @@ -70,8 +56,8 @@ public function getCancelUrl() { */ public function submitForm(array &$form, FormStateInterface $form_state) { $field_storage = $this->entity->getFieldStorageDefinition(); - $bundles = entity_get_bundles(); - $bundle_label = $bundles[$this->entity->entity_type][$this->entity->bundle]['label']; + $bundles = $this->entityManager->getBundleInfo($this->entity->entity_type); + $bundle_label = $bundles[$this->entity->bundle]['label']; if ($field_storage && !$field_storage->locked) { $this->entity->delete(); diff --git a/core/modules/field_ui/src/Tests/EntityDisplayModeTest.php b/core/modules/field_ui/src/Tests/EntityDisplayModeTest.php index a6ef8ee..7b7fe12 100644 --- a/core/modules/field_ui/src/Tests/EntityDisplayModeTest.php +++ b/core/modules/field_ui/src/Tests/EntityDisplayModeTest.php @@ -65,9 +65,9 @@ public function testEntityViewModeUI() { // Test deleting the view mode. $this->clickLink(t('Delete')); - $this->assertRaw(t('Are you sure you want to delete the %label view mode?', array('%label' => $edit['label']))); + $this->assertRaw(t('Are you sure you want to delete the view mode %label?', array('%label' => $edit['label']))); $this->drupalPostForm(NULL, NULL, t('Delete')); - $this->assertRaw(t('Deleted the %label view mode.', array('%label' => $edit['label']))); + $this->assertRaw(t('The view mode %label has been deleted.', array('%label' => $edit['label']))); } /** @@ -111,9 +111,9 @@ public function testEntityFormModeUI() { // Test deleting the form mode. $this->clickLink(t('Delete')); - $this->assertRaw(t('Are you sure you want to delete the %label form mode?', array('%label' => $edit['label']))); + $this->assertRaw(t('Are you sure you want to delete the form mode %label?', array('%label' => $edit['label']))); $this->drupalPostForm(NULL, NULL, t('Delete')); - $this->assertRaw(t('Deleted the %label form mode.', array('%label' => $edit['label']))); + $this->assertRaw(t('The form mode %label has been deleted.', array('%label' => $edit['label']))); } } diff --git a/core/modules/image/src/Form/ImageStyleDeleteForm.php b/core/modules/image/src/Form/ImageStyleDeleteForm.php index 05939fb..5c45d94 100644 --- a/core/modules/image/src/Form/ImageStyleDeleteForm.php +++ b/core/modules/image/src/Form/ImageStyleDeleteForm.php @@ -7,13 +7,13 @@ namespace Drupal\image\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Form\FormStateInterface; /** * Creates a form to delete an image style. */ -class ImageStyleDeleteForm extends EntityConfirmFormBase { +class ImageStyleDeleteForm extends EntityDeleteForm { /** * {@inheritdoc} @@ -21,21 +21,6 @@ class ImageStyleDeleteForm extends EntityConfirmFormBase { public function getQuestion() { return $this->t('Optionally select a style before deleting %style', array('%style' => $this->entity->label())); } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } - /** * {@inheritdoc} */ @@ -63,9 +48,8 @@ public function form(array $form, FormStateInterface $form_state) { */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->entity->set('replacementID', $form_state->getValue('replacement')); - $this->entity->delete(); - drupal_set_message($this->t('Style %name was deleted.', array('%name' => $this->entity->label()))); - $form_state->setRedirectUrl($this->getCancelUrl()); + + parent::submitForm($form, $form_state); } } diff --git a/core/modules/image/src/Tests/ImageAdminStylesTest.php b/core/modules/image/src/Tests/ImageAdminStylesTest.php index 8426337..df068ee 100644 --- a/core/modules/image/src/Tests/ImageAdminStylesTest.php +++ b/core/modules/image/src/Tests/ImageAdminStylesTest.php @@ -327,7 +327,7 @@ function testStyleReplacement() { 'replacement' => 'thumbnail', ); $this->drupalPostForm($style_path . $new_style_name . '/delete', $edit, t('Delete')); - $message = t('Style %name was deleted.', array('%name' => $new_style_label)); + $message = t('The image style %name has been deleted.', array('%name' => $new_style_label)); $this->assertRaw($message); $replacement_style = entity_load('image_style', 'thumbnail'); diff --git a/core/modules/language/src/Form/LanguageDeleteForm.php b/core/modules/language/src/Form/LanguageDeleteForm.php index f26948a..56b5fff 100644 --- a/core/modules/language/src/Form/LanguageDeleteForm.php +++ b/core/modules/language/src/Form/LanguageDeleteForm.php @@ -7,69 +7,13 @@ namespace Drupal\language\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Routing\UrlGeneratorInterface; -use Drupal\Core\Language\LanguageManagerInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Defines a confirmation form for deleting a language entity. */ -class LanguageDeleteForm extends EntityConfirmFormBase { - - /** - * The urlGenerator service. - * - * @var \Drupal\Core\Routing\UrlGeneratorInterface - */ - protected $urlGenerator; - - /** - * The language manager. - * - * @var \Drupal\Core\Language\LanguageManagerInterface - */ - protected $languageManager; - - /** - * Constructs a new LanguageDeleteForm object. - * - * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator - * The url generator service. - * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager - * The language manager. - */ - public function __construct(UrlGeneratorInterface $url_generator, LanguageManagerInterface $language_manager) { - $this->urlGenerator = $url_generator; - $this->languageManager = $language_manager; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('url_generator'), - $container->get('language_manager') - ); - } - - /** - * {@inheritdoc} - */ - public function getQuestion() { - return $this->t('Are you sure you want to delete the language %language?', array('%language' => $this->entity->label())); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } +class LanguageDeleteForm extends EntityDeleteForm { /** * {@inheritdoc} @@ -81,13 +25,6 @@ public function getDescription() { /** * {@inheritdoc} */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ public function getFormId() { return 'language_delete_form'; } @@ -95,35 +32,16 @@ public function getFormId() { /** * {@inheritdoc} */ - public function buildForm(array $form, FormStateInterface $form_state) { - $langcode = $this->entity->id(); - - // Warn and redirect user when attempting to delete the default language. - if ($this->languageManager->getDefaultLanguage()->getId() == $langcode) { - drupal_set_message($this->t('The default language cannot be deleted.')); - $url = $this->urlGenerator->generateFromPath('admin/config/regional/language', array('absolute' => TRUE)); - return new RedirectResponse($url); - } - - // Throw a 404 when attempting to delete a non-existing language. - $languages = $this->languageManager->getLanguages(); - if (!isset($languages[$langcode])) { - throw new NotFoundHttpException(); - } - return parent::buildForm($form, $form_state); + protected function getDeletionMessage() { + return $this->t('The %language (%langcode) language has been removed.', array('%language' => $this->entity->label(), '%langcode' => $this->entity->id())); } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); - $t_args = array('%language' => $this->entity->label(), '%langcode' => $this->entity->id()); - $this->logger('language')->notice('The %language (%langcode) language has been removed.', $t_args); - - drupal_set_message($this->t('The %language (%langcode) language has been removed.', $t_args)); - - $form_state->setRedirectUrl($this->getCancelUrl()); + parent::submitForm($form, $form_state); + $this->logger('language')->notice('The %language (%langcode) language has been removed.', array('%language' => $this->entity->label(), '%langcode' => $this->entity->id())); } } diff --git a/core/modules/language/src/LanguageAccessControlHandler.php b/core/modules/language/src/LanguageAccessControlHandler.php index 0490e91..72770e0 100644 --- a/core/modules/language/src/LanguageAccessControlHandler.php +++ b/core/modules/language/src/LanguageAccessControlHandler.php @@ -25,9 +25,14 @@ class LanguageAccessControlHandler extends EntityAccessControlHandler { public function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { switch ($operation) { case 'update': + /* @var \Drupal\Core\Language\LanguageInterface $entity */ + return AccessResult::allowedIf(!$entity->isLocked())->cacheUntilEntityChanges($entity) + ->andIf(parent::checkAccess($entity, $operation, $langcode, $account)); + case 'delete': /* @var \Drupal\Core\Language\LanguageInterface $entity */ return AccessResult::allowedIf(!$entity->isLocked())->cacheUntilEntityChanges($entity) + ->andIf(AccessResult::allowedIf(!$entity->isDefault())->cacheUntilEntityChanges($entity)) ->andIf(parent::checkAccess($entity, $operation, $langcode, $account)); default: diff --git a/core/modules/language/src/LanguageListBuilder.php b/core/modules/language/src/LanguageListBuilder.php index e392e75..5cf54b9 100644 --- a/core/modules/language/src/LanguageListBuilder.php +++ b/core/modules/language/src/LanguageListBuilder.php @@ -82,21 +82,6 @@ public function getFormId() { /** * {@inheritdoc} */ - public function getDefaultOperations(EntityInterface $entity) { - $operations = parent::getDefaultOperations($entity); - $default = $this->languageManager->getDefaultLanguage(); - - // Deleting the site default language is not allowed. - if ($entity->id() == $default->getId()) { - unset($operations['delete']); - } - - return $operations; - } - - /** - * {@inheritdoc} - */ public function buildHeader() { $header['label'] = t('Name'); return $header + parent::buildHeader(); diff --git a/core/modules/language/src/Tests/LanguageListTest.php b/core/modules/language/src/Tests/LanguageListTest.php index 52f6e4c..88e227f 100644 --- a/core/modules/language/src/Tests/LanguageListTest.php +++ b/core/modules/language/src/Tests/LanguageListTest.php @@ -75,10 +75,10 @@ function testLanguageList() { // Ensure we can't delete the default language. $this->drupalGet('admin/config/regional/language/delete/' . $langcode); - $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE, 'language' => $language])); - $this->assertText(t('The default language cannot be deleted.'), 'Failed to delete the default language.'); + $this->assertResponse(403, 'Failed to delete the default language.'); // Ensure 'Edit' link works. + $this->drupalGet('admin/config/regional/language'); $this->clickLink(t('Edit')); $this->assertTitle(t('Edit language | Drupal'), 'Page title is "Edit language".'); // Edit a language. diff --git a/core/modules/menu_link_content/src/Form/MenuLinkContentDeleteForm.php b/core/modules/menu_link_content/src/Form/MenuLinkContentDeleteForm.php index 882fdc9..dcc416d 100644 --- a/core/modules/menu_link_content/src/Form/MenuLinkContentDeleteForm.php +++ b/core/modules/menu_link_content/src/Form/MenuLinkContentDeleteForm.php @@ -7,54 +7,13 @@ namespace Drupal\menu_link_content\Form; -use Drupal\Core\Entity\ContentEntityConfirmFormBase; -use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Logger\LoggerChannelFactoryInterface; +use Drupal\Core\Entity\ContentEntityDeleteForm; use Drupal\Core\Url; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a delete form for content menu links. */ -class MenuLinkContentDeleteForm extends ContentEntityConfirmFormBase { - - /** - * Logger channel. - * - * @var \Drupal\Core\Logger\LoggerChannelInterface - */ - protected $logger; - - /** - * Constructs a MenuLinkContentDeleteForm object. - * - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. - * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory - * The logger channel factory. - */ - public function __construct(EntityManagerInterface $entity_manager, LoggerChannelFactoryInterface $logger_factory) { - parent::__construct($entity_manager); - $this->logger = $logger_factory->get('menu'); - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('entity.manager'), - $container->get('logger.factory') - ); - } - - /** - * {@inheritdoc} - */ - public function getQuestion() { - return $this->t('Are you sure you want to delete the custom menu link %item?', array('%item' => $this->entity->getTitle())); - } +class MenuLinkContentDeleteForm extends ContentEntityDeleteForm { /** * {@inheritdoc} @@ -66,12 +25,8 @@ public function getCancelUrl() { /** * {@inheritdoc} */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $t_args = array('%title' => $this->entity->getTitle()); - $this->entity->delete(); - drupal_set_message($this->t('The menu link %title has been deleted.', $t_args)); - $this->logger->notice('Deleted menu link %title.', $t_args); - $form_state->setRedirect(''); + protected function getDeletionMessage() { + return $this->t('The menu link %title has been deleted.', array('%title' => $this->entity->label())); } } diff --git a/core/modules/menu_ui/src/Form/MenuDeleteForm.php b/core/modules/menu_ui/src/Form/MenuDeleteForm.php index 17185d0..12a3d77 100644 --- a/core/modules/menu_ui/src/Form/MenuDeleteForm.php +++ b/core/modules/menu_ui/src/Form/MenuDeleteForm.php @@ -8,7 +8,7 @@ namespace Drupal\menu_ui\Form; use Drupal\Core\Database\Connection; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Menu\MenuLinkManagerInterface; use Drupal\Core\Form\FormStateInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -16,7 +16,7 @@ /** * Defines a confirmation form for deletion of a custom menu. */ -class MenuDeleteForm extends EntityConfirmFormBase { +class MenuDeleteForm extends EntityDeleteForm { /** * The menu link manager. @@ -58,20 +58,6 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public function getQuestion() { - return t('Are you sure you want to delete the custom menu %title?', array('%title' => $this->entity->label())); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return $this->entity->urlInfo('edit-form'); - } - - /** - * {@inheritdoc} - */ public function getDescription() { $caption = ''; $num_links = $this->menuLinkManager->countMenuLinks($this->entity->id()); @@ -85,16 +71,14 @@ public function getDescription() { /** * {@inheritdoc} */ - public function getConfirmText() { - return t('Delete'); + protected function logDeletionMessage() { + $this->logger('menu')->notice('Deleted custom menu %title and all its menu links.', array('%title' => $this->entity->label())); } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $form_state->setRedirectUrl($this->entity->urlInfo('collection')); - // Locked menus may not be deleted. if ($this->entity->isLocked()) { return; @@ -111,11 +95,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $this->menuLinkManager->removeDefinition($id); } - // Delete the custom menu and all its menu links. - $this->entity->delete(); - - $t_args = array('%title' => $this->entity->label()); - drupal_set_message(t('The custom menu %title has been deleted.', $t_args)); - $this->logger('menu')->notice('Deleted custom menu %title and all its menu links.', $t_args); + parent::submitForm($form, $form_state); + $form_state->setRedirect('menu_ui.overview_page'); } } diff --git a/core/modules/menu_ui/src/Tests/MenuTest.php b/core/modules/menu_ui/src/Tests/MenuTest.php index e33e53a..775dc5c 100644 --- a/core/modules/menu_ui/src/Tests/MenuTest.php +++ b/core/modules/menu_ui/src/Tests/MenuTest.php @@ -240,7 +240,7 @@ function deleteCustomMenu() { // Delete custom menu. $this->drupalPostForm("admin/structure/menu/manage/$menu_name/delete", array(), t('Delete')); $this->assertResponse(200); - $this->assertRaw(t('The custom menu %title has been deleted.', array('%title' => $label)), 'Custom menu was deleted'); + $this->assertRaw(t('The menu %title has been deleted.', array('%title' => $label)), 'Custom menu was deleted'); $this->assertNull(Menu::load($menu_name), 'Custom menu was deleted'); // Test if all menu links associated to the menu were removed from database. $result = entity_load_multiple_by_properties('menu_link_content', array('menu_name' => $menu_name)); @@ -739,7 +739,7 @@ function deleteMenuLink(MenuLinkContent $item) { $title = $item->getTitle(); // Delete menu link. - $this->drupalPostForm("admin/structure/menu/item/$mlid/delete", array(), t('Confirm')); + $this->drupalPostForm("admin/structure/menu/item/$mlid/delete", array(), t('Delete')); $this->assertResponse(200); $this->assertRaw(t('The menu link %title has been deleted.', array('%title' => $title)), 'Menu link was deleted'); diff --git a/core/modules/node/src/Form/NodeDeleteForm.php b/core/modules/node/src/Form/NodeDeleteForm.php index 2eceb06..16c86e6 100644 --- a/core/modules/node/src/Form/NodeDeleteForm.php +++ b/core/modules/node/src/Form/NodeDeleteForm.php @@ -7,67 +7,13 @@ namespace Drupal\node\Form; -use Drupal\Core\Entity\ContentEntityConfirmFormBase; -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\ContentEntityDeleteForm; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Routing\UrlGeneratorInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a form for deleting a node. */ -class NodeDeleteForm extends ContentEntityConfirmFormBase { - - /** - * The URL generator. - * - * @var \Drupal\Core\Routing\UrlGeneratorInterface - */ - protected $urlGenerator; - - /** - * Constructs a NodeDeleteForm object. - * - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. - * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator - * The URL generator. - */ - public function __construct(EntityManagerInterface $entity_manager, UrlGeneratorInterface $url_generator) { - parent::__construct($entity_manager); - $this->urlGenerator = $url_generator; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('entity.manager'), - $container->get('url_generator') - ); - } - - /** - * {@inheritdoc} - */ - public function getQuestion() { - return t('Are you sure you want to delete %title?', array('%title' => $this->entity->label())); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return $this->entity->urlInfo(); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return t('Delete'); - } +class NodeDeleteForm extends ContentEntityDeleteForm { /** * {@inheritdoc} diff --git a/core/modules/node/src/Form/NodeTypeDeleteConfirm.php b/core/modules/node/src/Form/NodeTypeDeleteConfirm.php index 31c4461..2367d8d 100644 --- a/core/modules/node/src/Form/NodeTypeDeleteConfirm.php +++ b/core/modules/node/src/Form/NodeTypeDeleteConfirm.php @@ -7,15 +7,15 @@ namespace Drupal\node\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; use Drupal\Core\Entity\Query\QueryFactory; +use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Form\FormStateInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a form for content type deletion. */ -class NodeTypeDeleteConfirm extends EntityConfirmFormBase { +class NodeTypeDeleteConfirm extends EntityDeleteForm { /** * The query factory to create entity queries. @@ -46,27 +46,6 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public function getQuestion() { - return t('Are you sure you want to delete the content type %type?', array('%type' => $this->entity->label())); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return t('Delete'); - } - - /** - * {@inheritdoc} - */ public function buildForm(array $form, FormStateInterface $form_state) { $num_nodes = $this->queryFactory->get('node') ->condition('type', $this->entity->id()) @@ -82,16 +61,4 @@ public function buildForm(array $form, FormStateInterface $form_state) { return parent::buildForm($form, $form_state); } - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); - $t_args = array('%name' => $this->entity->label()); - drupal_set_message(t('The content type %name has been deleted.', $t_args)); - $this->logger('node')->notice('Deleted content type %name.', $t_args); - - $form_state->setRedirectUrl($this->getCancelUrl()); - } - } diff --git a/core/modules/responsive_image/src/Entity/ResponsiveImageMapping.php b/core/modules/responsive_image/src/Entity/ResponsiveImageMapping.php index 87c0878..62215d8 100644 --- a/core/modules/responsive_image/src/Entity/ResponsiveImageMapping.php +++ b/core/modules/responsive_image/src/Entity/ResponsiveImageMapping.php @@ -21,7 +21,7 @@ * "form" = { * "edit" = "Drupal\responsive_image\ResponsiveImageMappingForm", * "add" = "Drupal\responsive_image\ResponsiveImageMappingForm", - * "delete" = "Drupal\responsive_image\Form\ResponsiveImageMappingDeleteForm", + * "delete" = "Drupal\Core\Entity\EntityDeleteForm", * "duplicate" = "Drupal\responsive_image\ResponsiveImageMappingForm" * } * }, diff --git a/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php b/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php deleted file mode 100644 index 5384134..0000000 --- a/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php +++ /dev/null @@ -1,47 +0,0 @@ -t('Are you sure you want to delete the responsive image mapping %title?', array('%title' => $this->entity->label())); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); - drupal_set_message($this->t('Responsive image mapping %label has been deleted.', array('%label' => $this->entity->label()))); - $this->logger('responsive_image')->notice('Responsive image mapping %label has been deleted.', array('%label' => $this->entity->label())); - $form_state->setRedirectUrl($this->getCancelUrl()); - } - -} diff --git a/core/modules/search/src/Entity/SearchPage.php b/core/modules/search/src/Entity/SearchPage.php index 4837906..1a1af60 100644 --- a/core/modules/search/src/Entity/SearchPage.php +++ b/core/modules/search/src/Entity/SearchPage.php @@ -30,7 +30,7 @@ * "add" = "Drupal\search\Form\SearchPageAddForm", * "edit" = "Drupal\search\Form\SearchPageEditForm", * "search" = "Drupal\search\Form\SearchPageForm", - * "delete" = "Drupal\search\Form\SearchPageDeleteForm" + * "delete" = "Drupal\Core\Entity\EntityDeleteForm" * } * }, * admin_permission = "administer search", diff --git a/core/modules/search/src/Form/SearchPageDeleteForm.php b/core/modules/search/src/Form/SearchPageDeleteForm.php deleted file mode 100644 index 53974fb..0000000 --- a/core/modules/search/src/Form/SearchPageDeleteForm.php +++ /dev/null @@ -1,48 +0,0 @@ -t('Are you sure you want to delete the %label search page?', array('%label' => $this->entity->label())); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); - $form_state->setRedirectUrl($this->getCancelUrl()); - drupal_set_message($this->t('The %label search page has been deleted.', array('%label' => $this->entity->label()))); - } - -} diff --git a/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php b/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php index 7d99214..45a9e8f 100644 --- a/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php +++ b/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php @@ -309,9 +309,9 @@ public function testMultipleSearchPages() { // Test deleting. $this->clickLink(t('Delete')); - $this->assertRaw(t('Are you sure you want to delete the %label search page?', array('%label' => $first['label']))); + $this->assertRaw(t('Are you sure you want to delete the search page %label?', array('%label' => $first['label']))); $this->drupalPostForm(NULL, array(), t('Delete')); - $this->assertRaw(t('The %label search page has been deleted.', array('%label' => $first['label']))); + $this->assertRaw(t('The search page %label has been deleted.', array('%label' => $first['label']))); $this->verifySearchPageOperations($first_id, FALSE, FALSE, FALSE, FALSE); } diff --git a/core/modules/shortcut/src/Form/ShortcutDeleteForm.php b/core/modules/shortcut/src/Form/ShortcutDeleteForm.php index 6d8ec7c..2b0ebb2 100644 --- a/core/modules/shortcut/src/Form/ShortcutDeleteForm.php +++ b/core/modules/shortcut/src/Form/ShortcutDeleteForm.php @@ -7,14 +7,13 @@ namespace Drupal\shortcut\Form; -use Drupal\Core\Entity\ContentEntityConfirmFormBase; -use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Entity\ContentEntityDeleteForm; use Drupal\Core\Url; /** * Builds the shortcut link deletion form. */ -class ShortcutDeleteForm extends ContentEntityConfirmFormBase { +class ShortcutDeleteForm extends ContentEntityDeleteForm { /** * {@inheritdoc} @@ -26,33 +25,10 @@ public function getFormId() { /** * {@inheritdoc} */ - public function getQuestion() { - return $this->t('Are you sure you want to delete the shortcut %title?', array('%title' => $this->entity->title->value)); - } - - /** - * {@inheritdoc} - */ public function getCancelUrl() { return new Url('entity.shortcut_set.customize_form', array( 'shortcut_set' => $this->entity->bundle(), )); } - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); - $form_state->setRedirectUrl($this->getCancelUrl()); - drupal_set_message($this->t('The shortcut %title has been deleted.', array('%title' => $this->entity->title->value))); - } - } diff --git a/core/modules/shortcut/src/Form/ShortcutSetDeleteForm.php b/core/modules/shortcut/src/Form/ShortcutSetDeleteForm.php index c38d191..06a4b5d 100644 --- a/core/modules/shortcut/src/Form/ShortcutSetDeleteForm.php +++ b/core/modules/shortcut/src/Form/ShortcutSetDeleteForm.php @@ -7,7 +7,7 @@ namespace Drupal\shortcut\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Form\FormStateInterface; use Drupal\shortcut\ShortcutSetStorageInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -16,7 +16,7 @@ /** * Builds the shortcut set deletion form. */ -class ShortcutSetDeleteForm extends EntityConfirmFormBase { +class ShortcutSetDeleteForm extends EntityDeleteForm { /** * The database connection. @@ -53,27 +53,6 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public function getQuestion() { - return t('Are you sure you want to delete the shortcut set %title?', array('%title' => $this->entity->label())); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return $this->entity->urlInfo('customize-form'); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return t('Delete'); - } - - /** - * {@inheritdoc} - */ public function buildForm(array $form, FormStateInterface $form_state) { // Find out how many users are directly assigned to this shortcut set, and // make a message. @@ -96,15 +75,6 @@ public function buildForm(array $form, FormStateInterface $form_state) { ); return parent::buildForm($form, $form_state); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); - $form_state->setRedirectUrl($this->entity->urlInfo('collection')); - drupal_set_message(t('The shortcut set %title has been deleted.', array('%title' => $this->entity->label()))); - } + } } diff --git a/core/modules/system/src/Form/DateFormatDeleteForm.php b/core/modules/system/src/Form/DateFormatDeleteForm.php index b71eb49..009700e 100644 --- a/core/modules/system/src/Form/DateFormatDeleteForm.php +++ b/core/modules/system/src/Form/DateFormatDeleteForm.php @@ -8,14 +8,13 @@ namespace Drupal\system\Form; use Drupal\Core\Datetime\DateFormatter; -use Drupal\Core\Entity\EntityConfirmFormBase; -use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Entity\EntityDeleteForm; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Builds a form to delete a date format. */ -class DateFormatDeleteForm extends EntityConfirmFormBase { +class DateFormatDeleteForm extends EntityDeleteForm { /** * The date formatter service. @@ -47,34 +46,10 @@ public static function create(ContainerInterface $container) { * {@inheritdoc} */ public function getQuestion() { - return t('Are you sure you want to remove the format %name : %format?', array( + return t('Are you sure you want to delete the format %name : %format?', array( '%name' => $this->entity->label(), '%format' => $this->dateFormatter->format(REQUEST_TIME, $this->entity->id())) ); } - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return t('Remove'); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); - drupal_set_message(t('Removed date format %format.', array('%format' => $this->entity->label()))); - - $form_state->setRedirectUrl($this->getCancelUrl()); - } - } diff --git a/core/modules/system/src/Tests/Entity/EntityFormTest.php b/core/modules/system/src/Tests/Entity/EntityFormTest.php index ce12dfe..307b69a 100644 --- a/core/modules/system/src/Tests/Entity/EntityFormTest.php +++ b/core/modules/system/src/Tests/Entity/EntityFormTest.php @@ -79,7 +79,7 @@ protected function doTestFormCRUD($entity_type) { $this->drupalGet($entity_type . '/manage/' . $entity->id()); $this->clickLink(t('Delete')); - $this->drupalPostForm(NULL, array(), t('Confirm')); + $this->drupalPostForm(NULL, array(), t('Delete')); $entity = $this->loadEntityByName($entity_type, $name2); $this->assertFalse($entity, format_string('%entity_type: Entity not found in the database.', array('%entity_type' => $entity_type))); } diff --git a/core/modules/system/src/Tests/System/DateTimeTest.php b/core/modules/system/src/Tests/System/DateTimeTest.php index f01f8c0..9176b1b 100644 --- a/core/modules/system/src/Tests/System/DateTimeTest.php +++ b/core/modules/system/src/Tests/System/DateTimeTest.php @@ -111,9 +111,9 @@ function testDateFormatConfiguration() { // Delete custom date format. $this->clickLink(t('Delete')); - $this->drupalPostForm('admin/config/regional/date-time/formats/manage/' . $date_format_id . '/delete', array(), t('Remove')); + $this->drupalPostForm('admin/config/regional/date-time/formats/manage/' . $date_format_id . '/delete', array(), t('Delete')); $this->assertUrl(\Drupal::url('entity.date_format.collection', [], ['absolute' => TRUE]), [], 'Correct page redirection.'); - $this->assertRaw(t('Removed date format %format.', array('%format' => $name)), 'Custom date format removed.'); + $this->assertRaw(t('The date format %format has been deleted.', array('%format' => $name)), 'Custom date format removed.'); // Make sure the date does not exist in config. $date_format = entity_load('date_format', $date_format_id); diff --git a/core/modules/system/tests/modules/entity_test/src/EntityTestDeleteForm.php b/core/modules/system/tests/modules/entity_test/src/EntityTestDeleteForm.php index f71f3e1..5cf2968 100644 --- a/core/modules/system/tests/modules/entity_test/src/EntityTestDeleteForm.php +++ b/core/modules/system/tests/modules/entity_test/src/EntityTestDeleteForm.php @@ -7,14 +7,13 @@ namespace Drupal\entity_test; -use Drupal\Core\Entity\ContentEntityConfirmFormBase; -use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Entity\ContentEntityDeleteForm; use Drupal\Core\Url; /** * Provides the entity_test delete form. */ -class EntityTestDeleteForm extends ContentEntityConfirmFormBase { +class EntityTestDeleteForm extends ContentEntityDeleteForm { /** * {@inheritdoc} @@ -23,23 +22,4 @@ public function getCancelUrl() { return new Url(''); } - /** - * {@inheritdoc} - */ - public function getQuestion() { - $entity_type = $this->entity->getEntityType(); - return t('Are you sure you want to delete the %label @entity-type?', array('%label' => $this->entity->label(), '@entity-type' => $entity_type->getLowercaseLabel())); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - parent::submitForm($form, $form_state); - $entity = $this->entity; - $entity->delete(); - drupal_set_message(t('%entity_type @id has been deleted.', array('@id' => $entity->id(), '%entity_type' => $entity->getEntityTypeId()))); - $form_state->setRedirectUrl($this->getCancelUrl()); - } - } diff --git a/core/modules/taxonomy/src/Form/TermDeleteForm.php b/core/modules/taxonomy/src/Form/TermDeleteForm.php index eaccb2b..fdbdf68 100644 --- a/core/modules/taxonomy/src/Form/TermDeleteForm.php +++ b/core/modules/taxonomy/src/Form/TermDeleteForm.php @@ -8,12 +8,13 @@ namespace Drupal\taxonomy\Form; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Entity\ContentEntityConfirmFormBase; +use Drupal\Core\Entity\ContentEntityDeleteForm; +use Drupal\Core\Url; /** * Provides a deletion confirmation form for taxonomy term. */ -class TermDeleteForm extends ContentEntityConfirmFormBase { +class TermDeleteForm extends ContentEntityDeleteForm { /** * {@inheritdoc} @@ -33,7 +34,9 @@ public function getQuestion() { * {@inheritdoc} */ public function getCancelUrl() { - return $this->entity->urlInfo('collection'); + // The cancel URL is the vocabulary collection, terms have no global + // list page. + return new Url('entity.taxonomy_vocabulary.collection'); } /** @@ -46,24 +49,22 @@ public function getDescription() { /** * {@inheritdoc} */ - public function getConfirmText() { - return $this->t('Delete'); + protected function getDeletionMessage() { + return $this->t('Deleted term %name.', array('%name' => $this->entity->label())); } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); + parent::submitForm($form, $form_state); + $storage = $this->entityManager->getStorage('taxonomy_vocabulary'); $vocabulary = $storage->load($this->entity->bundle()); // @todo Move to storage http://drupal.org/node/1988712 taxonomy_check_vocabulary_hierarchy($vocabulary, array('tid' => $this->entity->id())); - drupal_set_message($this->t('Deleted term %name.', array('%name' => $this->entity->getName()))); - $this->logger('taxonomy')->notice('Deleted term %name.', array('%name' => $this->entity->getName())); - $form_state->setRedirectUrl($this->getCancelUrl()); } } diff --git a/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php b/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php index 3f937b8..2e8c03b 100644 --- a/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php +++ b/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php @@ -7,13 +7,12 @@ namespace Drupal\taxonomy\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; -use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Entity\EntityDeleteForm; /** * Provides a deletion confirmation form for taxonomy vocabulary. */ -class VocabularyDeleteForm extends EntityConfirmFormBase { +class VocabularyDeleteForm extends EntityDeleteForm { /** * {@inheritdoc} @@ -32,13 +31,6 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } - - /** - * {@inheritdoc} - */ public function getDescription() { return $this->t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'); } @@ -46,18 +38,8 @@ public function getDescription() { /** * {@inheritdoc} */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); - drupal_set_message($this->t('Deleted vocabulary %name.', array('%name' => $this->entity->label()))); - $this->logger('taxonomy')->notice('Deleted vocabulary %name.', array('%name' => $this->entity->label())); - $form_state->setRedirectUrl($this->getCancelUrl()); + protected function getDeletionMessage() { + return $this->t('Deleted vocabulary %name.', array('%name' => $this->entity->label())); } } diff --git a/core/modules/user/src/Entity/Role.php b/core/modules/user/src/Entity/Role.php index b3dcdb5..e7e998d 100644 --- a/core/modules/user/src/Entity/Role.php +++ b/core/modules/user/src/Entity/Role.php @@ -24,7 +24,7 @@ * "list_builder" = "Drupal\user\RoleListBuilder", * "form" = { * "default" = "Drupal\user\RoleForm", - * "delete" = "Drupal\user\Form\UserRoleDelete" + * "delete" = "Drupal\Core\Entity\EntityDeleteForm" * } * }, * admin_permission = "administer permissions", diff --git a/core/modules/user/src/Form/UserRoleDelete.php b/core/modules/user/src/Form/UserRoleDelete.php deleted file mode 100644 index aa0f7d2..0000000 --- a/core/modules/user/src/Form/UserRoleDelete.php +++ /dev/null @@ -1,49 +0,0 @@ -t('Are you sure you want to delete the role %name?', array('%name' => $this->entity->label())); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); - $this->logger('user')->notice('Role %name has been deleted.', array('%name' => $this->entity->label())); - drupal_set_message($this->t('Role %name has been deleted.', array('%name' => $this->entity->label()))); - $form_state->setRedirectUrl($this->getCancelUrl()); - } - -} diff --git a/core/modules/user/src/Tests/UserRoleAdminTest.php b/core/modules/user/src/Tests/UserRoleAdminTest.php index 427ad8f..26f4d00 100644 --- a/core/modules/user/src/Tests/UserRoleAdminTest.php +++ b/core/modules/user/src/Tests/UserRoleAdminTest.php @@ -66,7 +66,7 @@ function testRoleAdministration() { $this->drupalGet("admin/people/roles/manage/{$role->id()}"); $this->clickLink(t('Delete')); $this->drupalPostForm(NULL, array(), t('Delete')); - $this->assertRaw(t('Role %label has been deleted.', array('%label' => $role_name))); + $this->assertRaw(t('The role %label has been deleted.', array('%label' => $role_name))); $this->assertNoLinkByHref("admin/people/roles/manage/{$role->id()}", 'Role edit link removed.'); \Drupal::entityManager()->getStorage('user_role')->resetCache(array($role->id())); $this->assertFalse(Role::load($role->id()), 'A deleted role can no longer be loaded.'); diff --git a/core/modules/views_ui/src/Tests/ViewEditTest.php b/core/modules/views_ui/src/Tests/ViewEditTest.php index 1dd7e0e..b46dd6b 100644 --- a/core/modules/views_ui/src/Tests/ViewEditTest.php +++ b/core/modules/views_ui/src/Tests/ViewEditTest.php @@ -38,7 +38,7 @@ public function testDeleteLink() { $this->clickLink(t('Delete view')); $this->assertUrl('admin/structure/views/view/test_view/delete'); $this->drupalPostForm(NULL, array(), t('Delete')); - $this->assertRaw(t('View %name deleted', array('%name' => $view->label()))); + $this->assertRaw(t('The view %name has been deleted.', array('%name' => $view->label()))); $this->assertUrl('admin/structure/views'); $view = $this->container->get('entity.manager')->getStorage('view')->load('test_view'); diff --git a/core/modules/views_ui/src/ViewDeleteForm.php b/core/modules/views_ui/src/ViewDeleteForm.php deleted file mode 100644 index 3c593ea..0000000 --- a/core/modules/views_ui/src/ViewDeleteForm.php +++ /dev/null @@ -1,49 +0,0 @@ -t('Are you sure you want to delete the %name view?', array('%name' => $this->entity->label())); - } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); - drupal_set_message($this->t('View %name deleted',array('%name' => $this->entity->label()))); - - $form_state->setRedirectUrl($this->getCancelUrl()); - } - -} diff --git a/core/modules/views_ui/views_ui.module b/core/modules/views_ui/views_ui.module index 5ac6790..f9f8996 100644 --- a/core/modules/views_ui/views_ui.module +++ b/core/modules/views_ui/views_ui.module @@ -50,7 +50,7 @@ function views_ui_entity_type_build(array &$entity_types) { ->setFormClass('add', 'Drupal\views_ui\ViewAddForm') ->setFormClass('preview', 'Drupal\views_ui\ViewPreviewForm') ->setFormClass('duplicate', 'Drupal\views_ui\ViewDuplicateForm') - ->setFormClass('delete', 'Drupal\views_ui\ViewDeleteForm') + ->setFormClass('delete', 'Drupal\Core\Entity\EntityDeleteForm') ->setFormClass('break_lock', 'Drupal\views_ui\Form\BreakLockForm') ->setListBuilderClass('Drupal\views_ui\ViewListBuilder') ->setLinkTemplate('edit-form', '/admin/structure/views/view/{view}')