diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php b/core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php index c365f37..590b80f 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php @@ -7,58 +7,11 @@ namespace Drupal\Core\Entity; -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Url; - /** * Provides a generic base class for a content entity deletion form. */ class ContentEntityDeleteForm extends ContentEntityConfirmFormBase { - /** - * {@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(), - )); - } - - /** - * {@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()); - } + use EntityDeleteFormTrait; } diff --git a/core/lib/Drupal/Core/Entity/EntityDeleteForm.php b/core/lib/Drupal/Core/Entity/EntityDeleteForm.php index e946ed6..71560a2 100644 --- a/core/lib/Drupal/Core/Entity/EntityDeleteForm.php +++ b/core/lib/Drupal/Core/Entity/EntityDeleteForm.php @@ -7,9 +7,6 @@ namespace Drupal\Core\Entity; -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Url; - /** * Provides a generic base class for an entity deletion form. * @@ -17,50 +14,6 @@ */ class EntityDeleteForm extends EntityConfirmFormBase { - /** - * {@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(), - )); - } - - /** - * {@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()); - } + use EntityDeleteFormTrait; } diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php b/core/lib/Drupal/Core/Entity/EntityDeleteFormTrait.php similarity index 83% copy from core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php copy to core/lib/Drupal/Core/Entity/EntityDeleteFormTrait.php index c365f37..085b34d 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php +++ b/core/lib/Drupal/Core/Entity/EntityDeleteFormTrait.php @@ -2,18 +2,20 @@ /** * @file - * Contains \Drupal\Core\Entity\ContentEntityDeleteForm. + * Contains \Drupal\Core\Entity\EntityDeleteFormTrait. */ namespace Drupal\Core\Entity; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Url; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** - * Provides a generic base class for a content entity deletion form. + * Provides a trait for an entity deletion form. + * + * @ingroup entity_api */ -class ContentEntityDeleteForm extends ContentEntityConfirmFormBase { +trait EntityDeleteFormTrait { /** * {@inheritdoc} @@ -29,7 +31,7 @@ public function getQuestion() { * {@inheritdoc} */ public function getConfirmText() { - return t('Delete'); + return $this->t('Delete'); } /** 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/contact/src/Form/ContactFormDeleteForm.php b/core/modules/contact/src/Form/ContactFormDeleteForm.php index a036f2e..6945f8d 100644 --- a/core/modules/contact/src/Form/ContactFormDeleteForm.php +++ b/core/modules/contact/src/Form/ContactFormDeleteForm.php @@ -7,21 +7,14 @@ namespace Drupal\contact\Form; -use Drupal\Core\Entity\EntityConfirmFormBase; +use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Builds the form to delete a contact form. */ -class ContactFormDeleteForm extends EntityConfirmFormBase { - - /** - * {@inheritdoc} - */ - public function getQuestion() { - return $this->t('Are you sure you want to delete %name?', array('%name' => $this->entity->label())); - } +class ContactFormDeleteForm extends EntityDeleteForm { /** * {@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(); - drupal_set_message($this->t('Contact form %label has been deleted.', array('%label' => $this->entity->label()))); + parent::submitForm($form, $form_state); $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 66176c4..711b0f0 100644 --- a/core/modules/contact/src/Tests/ContactSitewideTest.php +++ b/core/modules/contact/src/Tests/ContactSitewideTest.php @@ -412,7 +412,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/FieldConfigDeleteForm.php b/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php index b1ddb05..c7db81b 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); } diff --git a/core/modules/language/src/Form/LanguageDeleteForm.php b/core/modules/language/src/Form/LanguageDeleteForm.php index 1dbbaad..88b0865 100644 --- a/core/modules/language/src/Form/LanguageDeleteForm.php +++ b/core/modules/language/src/Form/LanguageDeleteForm.php @@ -9,11 +9,7 @@ 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\HttpKernel\Exception\NotFoundHttpException; /** * Defines a confirmation form for deleting a language entity. @@ -21,32 +17,6 @@ class LanguageDeleteForm extends EntityDeleteForm { /** - * The urlGenerator service. - * - * @var \Drupal\Core\Routing\UrlGeneratorInterface - */ - protected $urlGenerator; - - /** - * Constructs a new LanguageDeleteForm object. - * - * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator - * The url generator service. - */ - public function __construct(UrlGeneratorInterface $url_generator) { - $this->urlGenerator = $url_generator; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('url_generator') - ); - } - - /** * {@inheritdoc} */ public function getCancelUrl() { @@ -70,27 +40,6 @@ 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 (language_default()->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 = language_list(); - if (!isset($languages[$langcode])) { - throw new NotFoundHttpException(); - } - return parent::buildForm($form, $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())); } @@ -100,8 +49,7 @@ public function getDeletionMessage() { */ public function submitForm(array &$form, FormStateInterface $form_state) { 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); + $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..c2506d2 100644 --- a/core/modules/language/src/LanguageAccessControlHandler.php +++ b/core/modules/language/src/LanguageAccessControlHandler.php @@ -28,6 +28,7 @@ public function checkAccess(EntityInterface $entity, $operation, $langcode, Acco 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 42ec9d3..878fb31 100644 --- a/core/modules/language/src/LanguageListBuilder.php +++ b/core/modules/language/src/LanguageListBuilder.php @@ -45,21 +45,6 @@ public function getFormId() { /** * {@inheritdoc} */ - public function getDefaultOperations(EntityInterface $entity) { - $operations = parent::getDefaultOperations($entity); - $default = language_default(); - - // 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/menu_ui/src/Form/MenuDeleteForm.php b/core/modules/menu_ui/src/Form/MenuDeleteForm.php index 1672e4f..13b7221 100644 --- a/core/modules/menu_ui/src/Form/MenuDeleteForm.php +++ b/core/modules/menu_ui/src/Form/MenuDeleteForm.php @@ -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()); @@ -86,8 +72,6 @@ public function getDescription() { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $form_state->setRedirect('menu_ui.overview_page'); - // Locked menus may not be deleted. if ($this->entity->isLocked()) { return; @@ -104,11 +88,9 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $this->menuLinkManager->removeDefinition($id); } - // Delete the custom menu and all its menu links. - $this->entity->delete(); + parent::submitForm($form, $form_state); + $form_state->setRedirect('menu_ui.overview_page'); - $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); + $this->logger('menu')->notice('Deleted custom menu %title and all its menu links.', array('%title' => $this->entity->label())); } } diff --git a/core/modules/menu_ui/src/Tests/MenuTest.php b/core/modules/menu_ui/src/Tests/MenuTest.php index 2543ac2..aaa5a52 100644 --- a/core/modules/menu_ui/src/Tests/MenuTest.php +++ b/core/modules/menu_ui/src/Tests/MenuTest.php @@ -230,7 +230,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)); diff --git a/core/modules/taxonomy/src/Form/TermDeleteForm.php b/core/modules/taxonomy/src/Form/TermDeleteForm.php index 8a462c4..53ef0f9 100644 --- a/core/modules/taxonomy/src/Form/TermDeleteForm.php +++ b/core/modules/taxonomy/src/Form/TermDeleteForm.php @@ -26,6 +26,13 @@ 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'); } @@ -40,13 +47,6 @@ public function getDescription() { /** * {@inheritdoc} */ - public function getQuestion() { - return $this->t('Are you sure you want to delete the term %name?', array('%name' => $this->entity->label())); - } - - /** - * {@inheritdoc} - */ public function getDeletionMessage() { return $this->t('Deleted term %name.', array('%name' => $this->entity->label())); } diff --git a/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php b/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php index aa81fd3..8571464 100644 --- a/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php +++ b/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php @@ -26,6 +26,13 @@ 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'); } @@ -40,13 +47,6 @@ public function getDescription() { /** * {@inheritdoc} */ - public function getQuestion() { - return $this->t('Are you sure you want to delete the vocabulary %name?', array('%name' => $this->entity->label())); - } - - /** - * {@inheritdoc} - */ public function getDeletionMessage() { return $this->t('Deleted vocabulary %name.', array('%name' => $this->entity->label())); }