diff --git a/core/lib/Drupal/Core/Entity/EntityDeleteFormTrait.php b/core/lib/Drupal/Core/Entity/EntityDeleteFormTrait.php index 555bc49..888c401 100644 --- a/core/lib/Drupal/Core/Entity/EntityDeleteFormTrait.php +++ b/core/lib/Drupal/Core/Entity/EntityDeleteFormTrait.php @@ -20,12 +20,42 @@ trait EntityDeleteFormTrait { /** + * Translates a string to the current language or to a given language. + * + * Provided by \Drupal\Core\StringTranslation\StringTranslationTrait. + */ + abstract protected function t($string, array $args = array(), array $options = array(); + + /** + * Returns the entity of this form. + * + * Provided by \Drupal\Core\Entity\EntityForm. + * + * @return \Drupal\Core\Entity\EntityInterface + * The entity. + */ + abstract public function getEntity(); + + /** + * Gets the logger for a specific channel. + * + * Provided by \Drupal\Core\Form\FormBase. + * + * @param string $channel + * The name of the channel. + * + * @return \Psr\Log\LoggerInterface + * The logger for this channel. + */ + abstract protected function logger($channel); + + /** * {@inheritdoc} */ public function getQuestion() { - return t('Are you sure you want to delete the @entity-type %label?', array( - '@entity-type' => $this->entity->getEntityType()->getLowercaseLabel(), - '%label' => $this->entity->label(), + return $this->t('Are you sure you want to delete the @entity-type %label?', array( + '@entity-type' => $this->getEntity()->getEntityType()->getLowercaseLabel(), + '%label' => $this->getEntity()->label(), )); } @@ -43,9 +73,10 @@ public function getConfirmText() { * 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' => $this->entity->getEntityType()->getLowercaseLabel(), - '%label' => $this->entity->label(), + '@entity-type' => $entity->getEntityType()->getLowercaseLabel(), + '%label' => $entity->label(), )); } @@ -53,13 +84,14 @@ protected function getDeletionMessage() { * {@inheritdoc} */ public function getCancelUrl() { - if ($this->entity->hasLinkTemplate('collection')) { + $entity = $this->getEntity(); + if ($entity->hasLinkTemplate('collection')) { // If available, return the collection URL. - return $this->entity->urlInfo('collection'); + return $entity->urlInfo('collection'); } else { // Otherwise fall back to the default link template. - return $this->entity->urlInfo(); + return $entity->urlInfo(); } } @@ -67,9 +99,10 @@ public function getCancelUrl() { * Logs a message about the deleted entity. */ protected function logDeletionMessage() { - $this->logger($this->entity->getEntityType()->getProvider())->notice('The @entity-type %label has been deleted.', array( - '@entity-type' => $this->entity->getEntityType()->getLowercaseLabel(), - '%label' => $this->entity->label(), + $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(), )); } @@ -77,7 +110,7 @@ protected function logDeletionMessage() { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $this->entity->delete(); + $this->getEntity()->delete(); drupal_set_message($this->getDeletionMessage()); $form_state->setRedirectUrl($this->getCancelUrl()); $this->logDeletionMessage(); diff --git a/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php b/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php index ea33b45..a9ec5d9 100644 --- a/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php +++ b/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php @@ -47,13 +47,6 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } - - /** - * {@inheritdoc} - */ public function buildForm(array $form, FormStateInterface $form_state) { $blocks = $this->queryFactory->get('block_content')->condition('type', $this->entity->id())->execute(); if (!empty($blocks)) { diff --git a/core/modules/comment/src/Form/CommentTypeDeleteForm.php b/core/modules/comment/src/Form/CommentTypeDeleteForm.php index 1d702d2..9a859e8 100644 --- a/core/modules/comment/src/Form/CommentTypeDeleteForm.php +++ b/core/modules/comment/src/Form/CommentTypeDeleteForm.php @@ -91,13 +91,6 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } - - /** - * {@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(); 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 76a838a..0000000 --- a/core/modules/config/tests/config_test/src/Form/ConfigTestDeleteForm.php +++ /dev/null @@ -1,24 +0,0 @@ -entity->urlInfo('collection'); - } - -} 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 4d66e3c..0000000 --- a/core/modules/contact/src/Form/ContactFormDeleteForm.php +++ /dev/null @@ -1,25 +0,0 @@ -entity->urlInfo('collection'); - } - -} diff --git a/core/modules/field_ui/src/Form/EntityDisplayModeDeleteForm.php b/core/modules/field_ui/src/Form/EntityDisplayModeDeleteForm.php index 25f0d46..f244163 100644 --- a/core/modules/field_ui/src/Form/EntityDisplayModeDeleteForm.php +++ b/core/modules/field_ui/src/Form/EntityDisplayModeDeleteForm.php @@ -17,13 +17,6 @@ class EntityDisplayModeDeleteForm extends EntityDeleteForm { /** * {@inheritdoc} */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } - - /** - * {@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())); diff --git a/core/modules/image/src/Form/ImageStyleDeleteForm.php b/core/modules/image/src/Form/ImageStyleDeleteForm.php index 3f712f2..5c45d94 100644 --- a/core/modules/image/src/Form/ImageStyleDeleteForm.php +++ b/core/modules/image/src/Form/ImageStyleDeleteForm.php @@ -21,14 +21,6 @@ class ImageStyleDeleteForm extends EntityDeleteForm { public function getQuestion() { return $this->t('Optionally select a style before deleting %style', array('%style' => $this->entity->label())); } - - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } - /** * {@inheritdoc} */ diff --git a/core/modules/language/src/Form/LanguageDeleteForm.php b/core/modules/language/src/Form/LanguageDeleteForm.php index 5d461bc..56b5fff 100644 --- a/core/modules/language/src/Form/LanguageDeleteForm.php +++ b/core/modules/language/src/Form/LanguageDeleteForm.php @@ -18,13 +18,6 @@ class LanguageDeleteForm extends EntityDeleteForm { /** * {@inheritdoc} */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } - - /** - * {@inheritdoc} - */ public function getDescription() { return $this->t('Deleting a language will remove all interface translations associated with it, and content in this language will be set to be language neutral. This action cannot be undone.'); } diff --git a/core/modules/node/src/Form/NodeTypeDeleteConfirm.php b/core/modules/node/src/Form/NodeTypeDeleteConfirm.php index dfc012d..2367d8d 100644 --- a/core/modules/node/src/Form/NodeTypeDeleteConfirm.php +++ b/core/modules/node/src/Form/NodeTypeDeleteConfirm.php @@ -46,13 +46,6 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } - - /** - * {@inheritdoc} - */ public function buildForm(array $form, FormStateInterface $form_state) { $num_nodes = $this->queryFactory->get('node') ->condition('type', $this->entity->id()) 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 10f6cde..0000000 --- a/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php +++ /dev/null @@ -1,22 +0,0 @@ -entity->urlInfo('collection'); - } - -} 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 8f9323a..0000000 --- a/core/modules/search/src/Form/SearchPageDeleteForm.php +++ /dev/null @@ -1,24 +0,0 @@ -entity->urlInfo('collection'); - } - -} diff --git a/core/modules/shortcut/src/Form/ShortcutSetDeleteForm.php b/core/modules/shortcut/src/Form/ShortcutSetDeleteForm.php index 25c0913..06a4b5d 100644 --- a/core/modules/shortcut/src/Form/ShortcutSetDeleteForm.php +++ b/core/modules/shortcut/src/Form/ShortcutSetDeleteForm.php @@ -53,13 +53,6 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public function getCancelUrl() { - return $this->entity->urlInfo('customize-form'); - } - - /** - * {@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. @@ -82,6 +75,6 @@ public function buildForm(array $form, FormStateInterface $form_state) { ); return parent::buildForm($form, $form_state); - } + } } diff --git a/core/modules/system/src/Form/DateFormatDeleteForm.php b/core/modules/system/src/Form/DateFormatDeleteForm.php index 216a233..009700e 100644 --- a/core/modules/system/src/Form/DateFormatDeleteForm.php +++ b/core/modules/system/src/Form/DateFormatDeleteForm.php @@ -52,11 +52,4 @@ public function getQuestion() { ); } - /** - * {@inheritdoc} - */ - public function getCancelUrl() { - return $this->entity->urlInfo('collection'); - } - } diff --git a/core/modules/taxonomy/src/Form/TermDeleteForm.php b/core/modules/taxonomy/src/Form/TermDeleteForm.php index e4096dc..fdbdf68 100644 --- a/core/modules/taxonomy/src/Form/TermDeleteForm.php +++ b/core/modules/taxonomy/src/Form/TermDeleteForm.php @@ -9,6 +9,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Entity\ContentEntityDeleteForm; +use Drupal\Core\Url; /** * Provides a deletion confirmation form for taxonomy term. @@ -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'); } /** diff --git a/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php b/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php index 8bf3d26..2e8c03b 100644 --- a/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php +++ b/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php @@ -8,7 +8,6 @@ namespace Drupal\taxonomy\Form; use Drupal\Core\Entity\EntityDeleteForm; -use Drupal\Core\Form\FormStateInterface; /** * Provides a deletion confirmation form for taxonomy vocabulary. @@ -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.'); } 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 847973b..0000000 --- a/core/modules/user/src/Form/UserRoleDelete.php +++ /dev/null @@ -1,24 +0,0 @@ -entity->urlInfo('collection'); - } - -} diff --git a/core/modules/views_ui/src/ViewDeleteForm.php b/core/modules/views_ui/src/ViewDeleteForm.php deleted file mode 100644 index 47bb383..0000000 --- a/core/modules/views_ui/src/ViewDeleteForm.php +++ /dev/null @@ -1,24 +0,0 @@ -entity->urlInfo('collection'); - } - -} 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}')