diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php b/core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php new file mode 100644 index 0000000..eee3b5f --- /dev/null +++ b/core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php @@ -0,0 +1,64 @@ + $this->entity->getEntityType()->getLowercaseLabel(), + '%label' => $this->entity->label(), + )); + } + + /** + * {@inheritdoc} + */ + public function getConfirmText() { + return t('Delete'); + } + + /** + * Returns the message to display to the user after deleting the entity. + * + * @return string + * The translated string of the deletion message. + */ + public function getDeletionMessage() { + return $this->t('The @entity-type %label has been deleted.', array( + '@entity-type' => $this->entity->getEntityType()->getLowercaseLabel(), + '%label' => $this->entity->label(), + )); + } + + /** + * {@inheritdoc} + */ + public function getCancelUrl() { + return $this->entity->urlInfo(); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $this->entity->delete(); + drupal_set_message($this->getDeletionMessage()); + $form_state->setRedirectUrl($this->getCancelUrl()); + } + +} diff --git a/core/lib/Drupal/Core/Entity/EntityDeleteForm.php b/core/lib/Drupal/Core/Entity/EntityDeleteForm.php new file mode 100644 index 0000000..6062355 --- /dev/null +++ b/core/lib/Drupal/Core/Entity/EntityDeleteForm.php @@ -0,0 +1,66 @@ + $this->entity->getEntityType()->getLowercaseLabel(), + '%label' => $this->entity->label(), + )); + } + + /** + * {@inheritdoc} + */ + public function getConfirmText() { + return t('Delete'); + } + + /** + * Returns the message to display to the user after deleting the entity. + * + * @return string + * The translated string of the deletion message. + */ + public function getDeletionMessage() { + return $this->t('The @entity-type %label has been deleted.', array( + '@entity-type' => $this->entity->getEntityType()->getLowercaseLabel(), + '%label' => $this->entity->label(), + )); + } + + /** + * {@inheritdoc} + */ + public function getCancelUrl() { + return new $this->entity->urlInfo(); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $this->entity->delete(); + drupal_set_message($this->getDeletionMessage()); + $form_state->setRedirectUrl($this->getCancelUrl()); + } + +} diff --git a/core/modules/action/src/Form/ActionDeleteForm.php b/core/modules/action/src/Form/ActionDeleteForm.php index 86e5eef..90bcc62 100644 --- a/core/modules/action/src/Form/ActionDeleteForm.php +++ b/core/modules/action/src/Form/ActionDeleteForm.php @@ -7,28 +7,14 @@ namespace Drupal\action\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Form\FormStateInterface; 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} @@ -41,12 +27,9 @@ public function getCancelUrl() { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); + parent::submitForm($form, $form_state); $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..8043409 100644 --- a/core/modules/aggregator/src/Form/FeedDeleteForm.php +++ b/core/modules/aggregator/src/Form/FeedDeleteForm.php @@ -7,21 +7,14 @@ namespace Drupal\aggregator\Form; -use Drupal\Core\Entity\ContentEntityConfirmFormBase; +use Drupal\Core\Entity\ContentEntityDeleteForm; use Drupal\Core\Form\FormStateInterface; 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 +26,9 @@ public function getCancelUrl() { /** * {@inheritdoc} */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); + parent::submitForm($form, $form_state); $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'); } } 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_content/src/Form/BlockContentDeleteForm.php b/core/modules/block_content/src/Form/BlockContentDeleteForm.php index 1d7724d..71326bc 100644 --- a/core/modules/block_content/src/Form/BlockContentDeleteForm.php +++ b/core/modules/block_content/src/Form/BlockContentDeleteForm.php @@ -7,21 +7,14 @@ 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())); - } +class BlockContentDeleteForm extends ContentEntityDeleteForm { /** * {@inheritdoc} @@ -33,13 +26,6 @@ public function getCancelUrl() { /** * {@inheritdoc} */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ public function buildForm(array $form, FormStateInterface $form_state) { $instances = $this->entity->getInstances(); @@ -55,10 +41,8 @@ public function buildForm(array $form, FormStateInterface $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()))); + parent::submitForm($form, $form_state); $this->logger('block_content')->notice('Custom block %label has been deleted.', array('%label' => $this->entity->label())); - $form_state->setRedirect('block_content.list'); } } diff --git a/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php b/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php index 65fe352..1600b3e 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,13 +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 new Url('block_content.type_list'); } @@ -61,13 +54,6 @@ public function getCancelUrl() { /** * {@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)) { @@ -84,10 +70,8 @@ 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()))); + parent::submitForm($form, $form_state); $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/comment/src/Form/CommentTypeDeleteForm.php b/core/modules/comment/src/Form/CommentTypeDeleteForm.php index 7ac7ce7..c6f6b3f 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,13 +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 new Url('comment.type_list'); } @@ -105,13 +98,6 @@ public function getCancelUrl() { /** * {@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(); @@ -142,9 +128,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); - $form_state->setRedirect('comment.type_list'); - drupal_set_message($this->t('Comment type %label has been deleted.', array('%label' => $this->entity->label()))); + parent::submitForm($form, $form_state); $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..8f9bffc 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'); + public 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/config/tests/config_test/src/Form/ConfigTestDeleteForm.php b/core/modules/config/tests/config_test/src/Form/ConfigTestDeleteForm.php index 76fc67e..7990d89 100644 --- a/core/modules/config/tests/config_test/src/Form/ConfigTestDeleteForm.php +++ b/core/modules/config/tests/config_test/src/Form/ConfigTestDeleteForm.php @@ -6,29 +6,13 @@ namespace Drupal\config_test\Form; -use Drupal\Component\Utility\String; -use Drupal\Core\Entity\EntityConfirmFormBase; -use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Url; /** * Delete confirmation form for config_test entities. */ -class ConfigTestDeleteForm extends EntityConfirmFormBase { - - /** - * {@inheritdoc} - */ - public function getQuestion() { - return t('Are you sure you want to delete %label', array('%label' => $this->entity->label())); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return t('Delete'); - } +class ConfigTestDeleteForm extends EntityDeleteForm { /** * {@inheritdoc} @@ -37,13 +21,4 @@ public function getCancelUrl() { return new Url('config_test.list_page'); } - /** - * {@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/field_ui/src/Form/EntityDisplayModeDeleteForm.php b/core/modules/field_ui/src/Form/EntityDisplayModeDeleteForm.php index 315c918..4666d72 100644 --- a/core/modules/field_ui/src/Form/EntityDisplayModeDeleteForm.php +++ b/core/modules/field_ui/src/Form/EntityDisplayModeDeleteForm.php @@ -7,14 +7,14 @@ namespace Drupal\field_ui\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Provides the delete form for entity display modes. */ -class EntityDisplayModeDeleteForm extends EntityConfirmFormBase { +class EntityDisplayModeDeleteForm extends EntityDeleteForm { /** * {@inheritdoc} @@ -26,14 +26,6 @@ public function getCancelUrl() { /** * {@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 getDescription() { $entity_type = $this->entity->getEntityType(); 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())); @@ -42,19 +34,9 @@ public function getDescription() { /** * {@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(); + parent::submitForm($form, $form_state); \Drupal::entityManager()->clearCachedFieldDefinitions(); - $form_state->setRedirectUrl($this->getCancelUrl()); } } diff --git a/core/modules/image/src/Form/ImageStyleDeleteForm.php b/core/modules/image/src/Form/ImageStyleDeleteForm.php index 65dddac..7b763a1 100644 --- a/core/modules/image/src/Form/ImageStyleDeleteForm.php +++ b/core/modules/image/src/Form/ImageStyleDeleteForm.php @@ -7,14 +7,14 @@ namespace Drupal\image\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Creates a form to delete an image style. */ -class ImageStyleDeleteForm extends EntityConfirmFormBase { +class ImageStyleDeleteForm extends EntityDeleteForm { /** * {@inheritdoc} @@ -26,13 +26,6 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ public function getCancelUrl() { return new Url('image.style_list'); } @@ -64,9 +57,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/language/src/Form/LanguageDeleteForm.php b/core/modules/language/src/Form/LanguageDeleteForm.php index 32fb889..1dbbaad 100644 --- a/core/modules/language/src/Form/LanguageDeleteForm.php +++ b/core/modules/language/src/Form/LanguageDeleteForm.php @@ -7,19 +7,18 @@ 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\Url; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Defines a confirmation form for deleting a language entity. */ -class LanguageDeleteForm extends EntityConfirmFormBase { +class LanguageDeleteForm extends EntityDeleteForm { /** * The urlGenerator service. @@ -50,13 +49,6 @@ public static function create(ContainerInterface $container) { /** * {@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 new Url('language.admin_overview'); } @@ -71,13 +63,6 @@ public function getDescription() { /** * {@inheritdoc} */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ public function getFormId() { return 'language_delete_form'; } @@ -106,14 +91,17 @@ public function buildForm(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ + public 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(); + parent::submitForm($form, $form_state); $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()); } } diff --git a/core/modules/menu_link_content/src/Form/MenuLinkContentDeleteForm.php b/core/modules/menu_link_content/src/Form/MenuLinkContentDeleteForm.php index 882fdc9..39e724d 100644 --- a/core/modules/menu_link_content/src/Form/MenuLinkContentDeleteForm.php +++ b/core/modules/menu_link_content/src/Form/MenuLinkContentDeleteForm.php @@ -7,7 +7,7 @@ namespace Drupal\menu_link_content\Form; -use Drupal\Core\Entity\ContentEntityConfirmFormBase; +use Drupal\Core\Entity\ContentEntityDeleteForm; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Logger\LoggerChannelFactoryInterface; @@ -17,7 +17,7 @@ /** * Provides a delete form for content menu links. */ -class MenuLinkContentDeleteForm extends ContentEntityConfirmFormBase { +class MenuLinkContentDeleteForm extends ContentEntityDeleteForm { /** * Logger channel. @@ -52,13 +52,6 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public function getQuestion() { - return $this->t('Are you sure you want to delete the custom menu link %item?', array('%item' => $this->entity->getTitle())); - } - - /** - * {@inheritdoc} - */ public function getCancelUrl() { return new Url('entity.menu.edit_form', array('menu' => $this->entity->getMenuName())); } @@ -67,9 +60,8 @@ public function getCancelUrl() { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { + parent::submitForm($form, $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(''); } diff --git a/core/modules/menu_ui/src/Form/MenuDeleteForm.php b/core/modules/menu_ui/src/Form/MenuDeleteForm.php index 2d72b84..1672e4f 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. @@ -85,13 +85,6 @@ public function getDescription() { /** * {@inheritdoc} */ - public function getConfirmText() { - return t('Delete'); - } - - /** - * {@inheritdoc} - */ public function submitForm(array &$form, FormStateInterface $form_state) { $form_state->setRedirect('menu_ui.overview_page'); 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 0242301..5150238 100644 --- a/core/modules/node/src/Form/NodeTypeDeleteConfirm.php +++ b/core/modules/node/src/Form/NodeTypeDeleteConfirm.php @@ -7,8 +7,8 @@ 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 Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -16,7 +16,7 @@ /** * Provides a form for content type deletion. */ -class NodeTypeDeleteConfirm extends EntityConfirmFormBase { +class NodeTypeDeleteConfirm extends EntityDeleteForm { /** * The query factory to create entity queries. @@ -61,13 +61,6 @@ public function getCancelUrl() { /** * {@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()) @@ -87,12 +80,8 @@ public function buildForm(array $form, FormStateInterface $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()); + parent::submitForm($form, $form_state); + $this->logger('node')->notice('Deleted content type %name.', array('%name' => $this->entity->label())); } } diff --git a/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php b/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php index d5526b5..f553f8f 100644 --- a/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php +++ b/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php @@ -7,18 +7,11 @@ namespace Drupal\responsive_image\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; -class ResponsiveImageMappingDeleteForm extends EntityConfirmFormBase { - - /** - * {@inheritdoc} - */ - public function getQuestion() { - return $this->t('Are you sure you want to delete the responsive image mapping %title?', array('%title' => $this->entity->label())); - } +class ResponsiveImageMappingDeleteForm extends EntityDeleteForm { /** * {@inheritdoc} @@ -30,18 +23,9 @@ public function getCancelUrl() { /** * {@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()))); + parent::submitForm($form, $form_state); $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/Form/SearchPageDeleteForm.php b/core/modules/search/src/Form/SearchPageDeleteForm.php index 5518d59..eefbbf4 100644 --- a/core/modules/search/src/Form/SearchPageDeleteForm.php +++ b/core/modules/search/src/Form/SearchPageDeleteForm.php @@ -7,21 +7,13 @@ namespace Drupal\search\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; -use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Url; /** * Provides a deletion confirm form for search. */ -class SearchPageDeleteForm extends EntityConfirmFormBase { - - /** - * {@inheritdoc} - */ - public function getQuestion() { - return $this->t('Are you sure you want to delete the %label search page?', array('%label' => $this->entity->label())); - } +class SearchPageDeleteForm extends EntityDeleteForm { /** * {@inheritdoc} @@ -30,20 +22,4 @@ public function getCancelUrl() { return new Url('search.settings'); } - /** - * {@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/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 4ab3448..4848cf3 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,13 +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'); } @@ -67,13 +60,6 @@ public function getCancelUrl() { /** * {@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. @@ -98,13 +84,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(); - $form_state->setRedirect('shortcut.set_admin'); - 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 0cb8729..c2e64db 100644 --- a/core/modules/system/src/Form/DateFormatDeleteForm.php +++ b/core/modules/system/src/Form/DateFormatDeleteForm.php @@ -8,15 +8,14 @@ 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 Drupal\Core\Url; 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. @@ -48,7 +47,7 @@ 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())) ); @@ -57,25 +56,8 @@ public function getQuestion() { /** * {@inheritdoc} */ - public function getConfirmText() { - return t('Remove'); - } - - /** - * {@inheritdoc} - */ public function getCancelUrl() { return new Url('system.date_format_list'); } - /** - * {@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/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 77a3644..91fc7e4 100644 --- a/core/modules/taxonomy/src/Form/TermDeleteForm.php +++ b/core/modules/taxonomy/src/Form/TermDeleteForm.php @@ -11,12 +11,12 @@ use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Entity\ContentEntityConfirmFormBase; +use Drupal\Core\Entity\ContentEntityDeleteForm; /** * Provides a deletion confirmation form for taxonomy term. */ -class TermDeleteForm extends ContentEntityConfirmFormBase { +class TermDeleteForm extends ContentEntityDeleteForm { /** * {@inheritdoc} @@ -28,13 +28,6 @@ public function getFormId() { /** * {@inheritdoc} */ - public function getQuestion() { - return $this->t('Are you sure you want to delete the term %title?', array('%title' => $this->entity->getName())); - } - - /** - * {@inheritdoc} - */ public function getCancelUrl() { return new Url('taxonomy.vocabulary_list'); } @@ -49,24 +42,16 @@ public function getDescription() { /** * {@inheritdoc} */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@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 16ae285..447494c 100644 --- a/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php +++ b/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php @@ -7,14 +7,14 @@ namespace Drupal\taxonomy\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Provides a deletion confirmation form for taxonomy vocabulary. */ -class VocabularyDeleteForm extends EntityConfirmFormBase { +class VocabularyDeleteForm extends EntityDeleteForm { /** * {@inheritdoc} @@ -26,13 +26,6 @@ public function getFormId() { /** * {@inheritdoc} */ - public function getQuestion() { - return $this->t('Are you sure you want to delete the vocabulary %title?', array('%title' => $this->entity->label())); - } - - /** - * {@inheritdoc} - */ public function getCancelUrl() { return new Url('taxonomy.vocabulary_list'); } @@ -47,18 +40,10 @@ 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()))); + parent::submitForm($form, $form_state); + $this->logger('taxonomy')->notice('Deleted vocabulary %name.', array('%name' => $this->entity->label())); - $form_state->setRedirectUrl($this->getCancelUrl()); } } diff --git a/core/modules/user/src/Form/UserRoleDelete.php b/core/modules/user/src/Form/UserRoleDelete.php index 12d9662..a4740cd 100644 --- a/core/modules/user/src/Form/UserRoleDelete.php +++ b/core/modules/user/src/Form/UserRoleDelete.php @@ -7,21 +7,14 @@ namespace Drupal\user\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Provides a deletion confirmation form for Role entity. */ -class UserRoleDelete extends EntityConfirmFormBase { - - /** - * {@inheritdoc} - */ - public function getQuestion() { - return $this->t('Are you sure you want to delete the role %name?', array('%name' => $this->entity->label())); - } +class UserRoleDelete extends EntityDeleteForm { /** * {@inheritdoc} @@ -33,18 +26,10 @@ public function getCancelUrl() { /** * {@inheritdoc} */ - public function getConfirmText() { - return $this->t('Delete'); - } - - /** - * {@inheritdoc} - */ public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); + parent::submitForm($form, $form_state); + $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/views_ui/src/ViewDeleteForm.php b/core/modules/views_ui/src/ViewDeleteForm.php index 918b2ef..78df8f0 100644 --- a/core/modules/views_ui/src/ViewDeleteForm.php +++ b/core/modules/views_ui/src/ViewDeleteForm.php @@ -7,21 +7,13 @@ namespace Drupal\views_ui; -use Drupal\Core\Entity\EntityConfirmFormBase; -use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Url; /** * Provides a delete form for a view. */ -class ViewDeleteForm extends EntityConfirmFormBase { - - /** - * {@inheritdoc} - */ - public function getQuestion() { - return $this->t('Are you sure you want to delete the %name view?', array('%name' => $this->entity->label())); - } +class ViewDeleteForm extends EntityDeleteForm { /** * {@inheritdoc} @@ -30,21 +22,4 @@ public function getCancelUrl() { return new Url('views_ui.list'); } - /** - * {@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()); - } - }