Issue #1728804 by Berdir: Introduce (Content)EntityDeleteForm and children to handle entity deletions

8.0.x
Alex Pott 2015-01-30 10:46:14 +00:00
parent 9a5eb867cd
commit 9be3165caf
57 changed files with 269 additions and 1005 deletions

View File

@ -0,0 +1,17 @@
<?php
/**
* @file
* Contains \Drupal\Core\Entity\ContentEntityDeleteForm.
*/
namespace Drupal\Core\Entity;
/**
* Provides a generic base class for a content entity deletion form.
*/
class ContentEntityDeleteForm extends ContentEntityConfirmFormBase {
use EntityDeleteFormTrait;
}

View File

@ -0,0 +1,19 @@
<?php
/**
* @file
* Contains \Drupal\Core\Entity\EntityConfirmFormBase.
*/
namespace Drupal\Core\Entity;
/**
* Provides a generic base class for an entity deletion form.
*
* @ingroup entity_api
*/
class EntityDeleteForm extends EntityConfirmFormBase {
use EntityDeleteFormTrait;
}

View File

@ -0,0 +1,119 @@
<?php
/**
* @file
* Contains \Drupal\Core\Entity\EntityDeleteFormTrait.
*/
namespace Drupal\Core\Entity;
use Drupal\Core\Form\FormStateInterface;
/**
* Provides a trait for an entity deletion form.
*
* This trait relies on the StringTranslationTrait and the logger method added
* by FormBase.
*
* @ingroup entity_api
*/
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 $this->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();
}
}

View File

@ -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 @@ class ActionDeleteForm extends EntityConfirmFormBase {
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());
}
}

View File

@ -81,7 +81,7 @@ class ConfigurationTest extends WebTestBase {
$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.");

View File

@ -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 @@ class FeedDeleteForm extends ContentEntityConfirmFormBase {
/**
* {@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(),
));
}
}

View File

@ -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 @@ class BlockDeleteForm extends EntityConfirmFormBase {
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());
}
}

View File

@ -171,7 +171,7 @@ class BlockTest extends BlockTestBase {
$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 @@ class BlockTest extends BlockTestBase {
$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());
}

View File

@ -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 @@ class BlockContentDeleteForm extends ContentEntityConfirmFormBase {
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'));
}
}

View File

@ -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 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* 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.
@ -44,27 +44,6 @@ class BlockContentTypeDeleteForm extends EntityConfirmFormBase {
);
}
/**
* {@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}
*/
@ -80,14 +59,4 @@ class BlockContentTypeDeleteForm extends EntityConfirmFormBase {
}
}
/**
* {@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());
}
}

View File

@ -227,7 +227,7 @@ class BlockContentCreationTest extends BlockContentTestBase {
$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();

View File

@ -99,7 +99,7 @@ class BlockContentListTest extends BlockContentTestBase {
$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

View File

@ -126,7 +126,7 @@ class BlockContentTypeTest extends BlockContentTestBase {
// 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.');

View File

@ -61,7 +61,7 @@ class PageEditTest extends BlockContentTestBase {
// 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())));
}
}

View File

@ -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 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* 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.
@ -88,27 +88,6 @@ class CommentTypeDeleteForm extends EntityConfirmFormBase {
);
}
/**
* {@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}
*/
@ -138,14 +117,4 @@ class CommentTypeDeleteForm extends EntityConfirmFormBase {
}
}
/**
* {@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()));
}
}

View File

@ -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,15 @@ class DeleteForm extends ContentEntityConfirmFormBase {
/**
* {@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.'));
public function logDeletionMessage() {
$this->logger('content')->notice('Deleted comment @cid and its replies.', array('@cid' => $this->entity->id()));
$form_state->setRedirectUrl($this->getCancelUrl());
}
}

View File

@ -169,7 +169,7 @@ class CommentTypeTest extends CommentTestBase {
// 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 @@ class CommentTypeTest extends CommentTestBase {
// 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())));
}
}

View File

@ -214,7 +214,7 @@ class ConfigEntityListTest extends WebTestBase {
$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 @@ class ConfigEntityListTest extends WebTestBase {
// 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

View File

@ -241,7 +241,7 @@ class ConfigEntityTest extends WebTestBase {
$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(

View File

@ -23,7 +23,7 @@ use Drupal\Core\Entity\EntityStorageInterface;
* "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"
* },

View File

@ -1,49 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\config_test\Form\ConfigTestDeleteForm.
*/
namespace Drupal\config_test\Form;
use Drupal\Component\Utility\String;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
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');
}
/**
* {@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());
}
}

View File

@ -23,7 +23,7 @@ use Drupal\Core\Config\Entity\ThirdPartySettingsTrait;
* "form" = {
* "add" = "Drupal\contact\ContactFormEditForm",
* "edit" = "Drupal\contact\ContactFormEditForm",
* "delete" = "Drupal\contact\Form\ContactFormDeleteForm"
* "delete" = "Drupal\Core\Entity\EntityDeleteForm"
* }
* },
* config_prefix = "form",

View File

@ -1,50 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\contact\Form\ContactFormDeleteDeleteForm.
*/
namespace Drupal\contact\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
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()));
}
/**
* {@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());
}
}

View File

@ -414,7 +414,7 @@ class ContactSitewideTest extends WebTestBase {
}
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())));
}
}

View File

@ -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 @@ class EntityDisplayModeDeleteForm extends EntityConfirmFormBase {
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());
}
}

View File

@ -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 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a form for removing a field from a bundle.
*/
class FieldConfigDeleteForm extends EntityConfirmFormBase {
class FieldConfigDeleteForm extends EntityDeleteForm {
/**
* The entity manager.
@ -44,20 +44,6 @@ class FieldConfigDeleteForm extends EntityConfirmFormBase {
);
}
/**
* {@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}
*/
@ -70,8 +56,8 @@ class FieldConfigDeleteForm extends EntityConfirmFormBase {
*/
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();

View File

@ -65,9 +65,9 @@ class EntityDisplayModeTest extends WebTestBase {
// 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 @@ class EntityDisplayModeTest extends WebTestBase {
// 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'])));
}
}

View File

@ -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 @@ class ImageStyleDeleteForm extends EntityConfirmFormBase {
*/
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);
}
}

View File

@ -327,7 +327,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase {
'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');

View File

@ -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}
@ -78,13 +22,6 @@ class LanguageDeleteForm extends EntityConfirmFormBase {
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.');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Delete');
}
/**
* {@inheritdoc}
*/
@ -95,35 +32,15 @@ class LanguageDeleteForm extends EntityConfirmFormBase {
/**
* {@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());
public function logDeletionMessage() {
$this->logger('language')->notice('The %language (%langcode) language has been removed.', array('%language' => $this->entity->label(), '%langcode' => $this->entity->id()));
}
}

View File

@ -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:

View File

@ -79,21 +79,6 @@ class LanguageListBuilder extends DraggableListBuilder {
return 'language_admin_overview_form';
}
/**
* {@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}
*/

View File

@ -75,10 +75,10 @@ class LanguageListTest extends WebTestBase {
// 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.

View File

@ -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 @@ class MenuLinkContentDeleteForm extends ContentEntityConfirmFormBase {
/**
* {@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('<front>');
protected function getDeletionMessage() {
return $this->t('The menu link %title has been deleted.', array('%title' => $this->entity->label()));
}
}

View File

@ -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 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines a confirmation form for deletion of a custom menu.
*/
class MenuDeleteForm extends EntityConfirmFormBase {
class MenuDeleteForm extends EntityDeleteForm {
/**
* The menu link manager.
@ -55,20 +55,6 @@ class MenuDeleteForm extends EntityConfirmFormBase {
);
}
/**
* {@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}
*/
@ -85,16 +71,14 @@ class MenuDeleteForm extends EntityConfirmFormBase {
/**
* {@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,6 @@ class MenuDeleteForm extends EntityConfirmFormBase {
$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);
}
}

View File

@ -240,7 +240,7 @@ class MenuTest extends MenuWebTestBase {
// 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 @@ class MenuTest extends MenuWebTestBase {
$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');

View File

@ -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}

View File

@ -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.
@ -43,27 +43,6 @@ class NodeTypeDeleteConfirm extends EntityConfirmFormBase {
);
}
/**
* {@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}
*/
@ -82,16 +61,4 @@ class NodeTypeDeleteConfirm extends EntityConfirmFormBase {
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());
}
}

View File

@ -21,7 +21,7 @@ use Drupal\responsive_image\ResponsiveImageMappingInterface;
* "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"
* }
* },

View File

@ -1,47 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\responsive_image\Form\ResponsiveImageMappingActionConfirm.
*/
namespace Drupal\responsive_image\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
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()));
}
/**
* {@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());
}
}

View File

@ -30,7 +30,7 @@ use Drupal\search\SearchPageInterface;
* "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",

View File

@ -1,48 +0,0 @@
<?php
/**
* @file
* Contains Drupal\search\Form\SearchPageDeleteForm.
*/
namespace Drupal\search\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* 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()));
}
/**
* {@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())));
}
}

View File

@ -311,9 +311,9 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
// 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);
}

View File

@ -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}
@ -23,13 +22,6 @@ class ShortcutDeleteForm extends ContentEntityConfirmFormBase {
return 'shortcut_confirm_delete';
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete the shortcut %title?', array('%title' => $this->entity->getTitle()));
}
/**
* {@inheritdoc}
*/
@ -39,20 +31,4 @@ class ShortcutDeleteForm extends ContentEntityConfirmFormBase {
));
}
/**
* {@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)));
}
}

View File

@ -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 @@ use Drupal\Core\Database\Connection;
/**
* Builds the shortcut set deletion form.
*/
class ShortcutSetDeleteForm extends EntityConfirmFormBase {
class ShortcutSetDeleteForm extends EntityDeleteForm {
/**
* The database connection.
@ -50,27 +50,6 @@ class ShortcutSetDeleteForm extends EntityConfirmFormBase {
);
}
/**
* {@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}
*/
@ -96,15 +75,6 @@ class ShortcutSetDeleteForm extends EntityConfirmFormBase {
);
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())));
}
}
}

View File

@ -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 @@ class DateFormatDeleteForm extends EntityConfirmFormBase {
* {@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());
}
}

View File

@ -79,7 +79,7 @@ class EntityFormTest extends WebTestBase {
$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)));
}

View File

@ -111,9 +111,9 @@ class DateTimeTest extends WebTestBase {
// 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);

View File

@ -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 @@ class EntityTestDeleteForm extends ContentEntityConfirmFormBase {
return new Url('<front>');
}
/**
* {@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());
}
}

View File

@ -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 @@ class TermDeleteForm extends ContentEntityConfirmFormBase {
* {@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 @@ class TermDeleteForm extends ContentEntityConfirmFormBase {
/**
* {@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());
}
}

View File

@ -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}
@ -29,13 +28,6 @@ class VocabularyDeleteForm extends EntityConfirmFormBase {
return $this->t('Are you sure you want to delete the vocabulary %title?', array('%title' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return $this->entity->urlInfo('collection');
}
/**
* {@inheritdoc}
*/
@ -46,18 +38,8 @@ class VocabularyDeleteForm extends EntityConfirmFormBase {
/**
* {@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()));
}
}

View File

@ -24,7 +24,7 @@ use Drupal\user\RoleInterface;
* "list_builder" = "Drupal\user\RoleListBuilder",
* "form" = {
* "default" = "Drupal\user\RoleForm",
* "delete" = "Drupal\user\Form\UserRoleDelete"
* "delete" = "Drupal\Core\Entity\EntityDeleteForm"
* }
* },
* admin_permission = "administer permissions",

View File

@ -1,49 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\user\Form\UserRoleDelete.
*/
namespace Drupal\user\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* 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()));
}
/**
* {@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());
}
}

View File

@ -66,7 +66,7 @@ class UserRoleAdminTest extends WebTestBase {
$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.');

View File

@ -38,7 +38,7 @@ class ViewEditTest extends UITestBase {
$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');

View File

@ -1,49 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\views_ui\ViewDeleteForm.
*/
namespace Drupal\views_ui;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* 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()));
}
/**
* {@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());
}
}

View File

@ -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}')