diff --git a/core/lib/Drupal/Core/Entity/EntityDeleteFormTrait.php b/core/lib/Drupal/Core/Entity/EntityDeleteFormTrait.php index 085b34d..66a21d0 100644 --- a/core/lib/Drupal/Core/Entity/EntityDeleteFormTrait.php +++ b/core/lib/Drupal/Core/Entity/EntityDeleteFormTrait.php @@ -8,11 +8,13 @@ namespace Drupal\Core\Entity; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\StringTranslation\StringTranslationTrait; /** * 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 { @@ -40,7 +42,7 @@ public function getConfirmText() { * @return string * The translated string of the deletion message. */ - public function getDeletionMessage() { + protected function getDeletionMessage() { return $this->t('The @entity-type %label has been deleted.', array( '@entity-type' => $this->entity->getEntityType()->getLowercaseLabel(), '%label' => $this->entity->label(), @@ -55,12 +57,23 @@ 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(), + )); + } + + /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->entity->delete(); drupal_set_message($this->getDeletionMessage()); $form_state->setRedirectUrl($this->getCancelUrl()); + $this->logDeletionMessage(); } } diff --git a/core/modules/action/src/Form/ActionDeleteForm.php b/core/modules/action/src/Form/ActionDeleteForm.php index 90bcc62..69f1b15 100644 --- a/core/modules/action/src/Form/ActionDeleteForm.php +++ b/core/modules/action/src/Form/ActionDeleteForm.php @@ -8,7 +8,6 @@ namespace Drupal\action\Form; use Drupal\Core\Entity\EntityDeleteForm; -use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** @@ -23,13 +22,4 @@ public function getCancelUrl() { return new Url('action.admin'); } - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - parent::submitForm($form, $form_state); - - $this->logger('user')->notice('Deleted action %aid (%action)', array('%aid' => $this->entity->id(), '%action' => $this->entity->label())); - } - } diff --git a/core/modules/aggregator/src/Form/FeedDeleteForm.php b/core/modules/aggregator/src/Form/FeedDeleteForm.php index 7ebba1c..2acab06 100644 --- a/core/modules/aggregator/src/Form/FeedDeleteForm.php +++ b/core/modules/aggregator/src/Form/FeedDeleteForm.php @@ -8,7 +8,6 @@ namespace Drupal\aggregator\Form; use Drupal\Core\Entity\ContentEntityDeleteForm; -use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** @@ -26,18 +25,10 @@ public function getCancelUrl() { /** * {@inheritdoc} */ - public function getDeletionMessage() { + protected function getDeletionMessage() { return $this->t('The feed %label has been deleted.', array( '%label' => $this->entity->label(), )); } - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - parent::submitForm($form, $form_state); - $this->logger('aggregator')->notice('Feed %feed deleted.', array('%feed' => $this->entity->label())); - } - } diff --git a/core/modules/block_content/src/Form/BlockContentDeleteForm.php b/core/modules/block_content/src/Form/BlockContentDeleteForm.php index 31a3e7e..455d383 100644 --- a/core/modules/block_content/src/Form/BlockContentDeleteForm.php +++ b/core/modules/block_content/src/Form/BlockContentDeleteForm.php @@ -37,13 +37,4 @@ public function buildForm(array $form, FormStateInterface $form_state) { return parent::buildForm($form, $form_state); } - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - parent::submitForm($form, $form_state); - $this->logger('block_content')->notice('Custom block %label has been deleted.', array('%label' => $this->entity->label())); - $form_state->setRedirect('block_content.list'); - } - } diff --git a/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php b/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php index 1600b3e..c15eb2e 100644 --- a/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php +++ b/core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php @@ -66,12 +66,4 @@ public function buildForm(array $form, FormStateInterface $form_state) { } } - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - parent::submitForm($form, $form_state); - $this->logger('block_content')->notice('Custom block type %label has been deleted.', array('%label' => $this->entity->label())); - } - } diff --git a/core/modules/comment/src/Form/DeleteForm.php b/core/modules/comment/src/Form/DeleteForm.php index 8f9bffc..4e995bb 100644 --- a/core/modules/comment/src/Form/DeleteForm.php +++ b/core/modules/comment/src/Form/DeleteForm.php @@ -33,7 +33,7 @@ public function getDescription() { /** * {@inheritdoc} */ - public function getDeletionMessage() { + protected function getDeletionMessage() { return $this->t('The comment and all its replies have been deleted.'); } diff --git a/core/modules/contact/src/Form/ContactFormDeleteForm.php b/core/modules/contact/src/Form/ContactFormDeleteForm.php index 6945f8d..f448c67 100644 --- a/core/modules/contact/src/Form/ContactFormDeleteForm.php +++ b/core/modules/contact/src/Form/ContactFormDeleteForm.php @@ -8,7 +8,6 @@ namespace Drupal\contact\Form; use Drupal\Core\Entity\EntityDeleteForm; -use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** @@ -23,12 +22,4 @@ public function getCancelUrl() { return new Url('contact.form_list'); } - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - parent::submitForm($form, $form_state); - $this->logger('contact')->notice('Contact form %label has been deleted.', array('%label' => $this->entity->label())); - } - } diff --git a/core/modules/field_ui/src/Form/EntityDisplayModeDeleteForm.php b/core/modules/field_ui/src/Form/EntityDisplayModeDeleteForm.php index 4666d72..f4e51a8 100644 --- a/core/modules/field_ui/src/Form/EntityDisplayModeDeleteForm.php +++ b/core/modules/field_ui/src/Form/EntityDisplayModeDeleteForm.php @@ -8,7 +8,6 @@ namespace Drupal\field_ui\Form; use Drupal\Core\Entity\EntityDeleteForm; -use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** @@ -31,12 +30,4 @@ public function getDescription() { return t('Deleting a @entity-type will cause any output still requesting to use that @entity-type to use the default display settings.', array('@entity-type' => $entity_type->getLowercaseLabel())); } - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - parent::submitForm($form, $form_state); - \Drupal::entityManager()->clearCachedFieldDefinitions(); - } - } diff --git a/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php b/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php index c7db81b..4afe0e3 100644 --- a/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php +++ b/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php @@ -56,8 +56,8 @@ public function getCancelUrl() { */ public function submitForm(array &$form, FormStateInterface $form_state) { $field_storage = $this->entity->getFieldStorageDefinition(); - $bundles = entity_get_bundles(); - $bundle_label = $bundles[$this->entity->entity_type][$this->entity->bundle]['label']; + $bundles = $this->entityManager->getBundleInfo($this->entity->entity_type); + $bundle_label = $bundles[$this->entity->bundle]['label']; if ($field_storage && !$field_storage->locked) { $this->entity->delete(); diff --git a/core/modules/language/src/Form/LanguageDeleteForm.php b/core/modules/language/src/Form/LanguageDeleteForm.php index 88b0865..fe040dc 100644 --- a/core/modules/language/src/Form/LanguageDeleteForm.php +++ b/core/modules/language/src/Form/LanguageDeleteForm.php @@ -40,7 +40,7 @@ public function getFormId() { /** * {@inheritdoc} */ - public function getDeletionMessage() { + protected function getDeletionMessage() { return $this->t('The %language (%langcode) language has been removed.', array('%language' => $this->entity->label(), '%langcode' => $this->entity->id())); } diff --git a/core/modules/menu_link_content/src/Form/MenuLinkContentDeleteForm.php b/core/modules/menu_link_content/src/Form/MenuLinkContentDeleteForm.php index ae742c6..dcc416d 100644 --- a/core/modules/menu_link_content/src/Form/MenuLinkContentDeleteForm.php +++ b/core/modules/menu_link_content/src/Form/MenuLinkContentDeleteForm.php @@ -8,11 +8,7 @@ namespace Drupal\menu_link_content\Form; use Drupal\Core\Entity\ContentEntityDeleteForm; -use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Url; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a delete form for content menu links. @@ -20,36 +16,6 @@ class MenuLinkContentDeleteForm extends ContentEntityDeleteForm { /** - * 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 getCancelUrl() { @@ -59,17 +25,8 @@ public function getCancelUrl() { /** * {@inheritdoc} */ - public function getDeletionMessage() { + protected function getDeletionMessage() { return $this->t('The menu link %title has been deleted.', array('%title' => $this->entity->label())); } - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - parent::submitForm($form, $form_state); - $t_args = array('%title' => $this->entity->getTitle()); - $this->logger->notice('Deleted menu link %title.', $t_args); - } - } diff --git a/core/modules/menu_ui/src/Form/MenuDeleteForm.php b/core/modules/menu_ui/src/Form/MenuDeleteForm.php index 13b7221..ad24bcb 100644 --- a/core/modules/menu_ui/src/Form/MenuDeleteForm.php +++ b/core/modules/menu_ui/src/Form/MenuDeleteForm.php @@ -71,6 +71,13 @@ public function getDescription() { /** * {@inheritdoc} */ + 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) { // Locked menus may not be deleted. if ($this->entity->isLocked()) { @@ -90,7 +97,5 @@ public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); $form_state->setRedirect('menu_ui.overview_page'); - - $this->logger('menu')->notice('Deleted custom menu %title and all its menu links.', array('%title' => $this->entity->label())); } } diff --git a/core/modules/node/src/Form/NodeTypeDeleteConfirm.php b/core/modules/node/src/Form/NodeTypeDeleteConfirm.php index 5150238..9ab8529 100644 --- a/core/modules/node/src/Form/NodeTypeDeleteConfirm.php +++ b/core/modules/node/src/Form/NodeTypeDeleteConfirm.php @@ -47,13 +47,6 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public function getQuestion() { - return t('Are you sure you want to delete the content type %type?', array('%type' => $this->entity->label())); - } - - /** - * {@inheritdoc} - */ public function getCancelUrl() { return new Url('node.overview_types'); } @@ -76,12 +69,4 @@ public function buildForm(array $form, FormStateInterface $form_state) { return parent::buildForm($form, $form_state); } - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - parent::submitForm($form, $form_state); - $this->logger('node')->notice('Deleted content type %name.', array('%name' => $this->entity->label())); - } - } diff --git a/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php b/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php index f553f8f..a611820 100644 --- a/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php +++ b/core/modules/responsive_image/src/Form/ResponsiveImageMappingDeleteForm.php @@ -8,7 +8,6 @@ namespace Drupal\responsive_image\Form; use Drupal\Core\Entity\EntityDeleteForm; -use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; class ResponsiveImageMappingDeleteForm extends EntityDeleteForm { @@ -20,12 +19,4 @@ public function getCancelUrl() { return new Url('responsive_image.mapping_page'); } - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - parent::submitForm($form, $form_state); - $this->logger('responsive_image')->notice('Responsive image mapping %label has been deleted.', array('%label' => $this->entity->label())); - } - } diff --git a/core/modules/taxonomy/src/Form/TermDeleteForm.php b/core/modules/taxonomy/src/Form/TermDeleteForm.php index 53ef0f9..1d0839a 100644 --- a/core/modules/taxonomy/src/Form/TermDeleteForm.php +++ b/core/modules/taxonomy/src/Form/TermDeleteForm.php @@ -47,7 +47,7 @@ public function getDescription() { /** * {@inheritdoc} */ - public function getDeletionMessage() { + protected function getDeletionMessage() { return $this->t('Deleted term %name.', array('%name' => $this->entity->label())); } @@ -63,7 +63,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // @todo Move to storage http://drupal.org/node/1988712 taxonomy_check_vocabulary_hierarchy($vocabulary, array('tid' => $this->entity->id())); - $this->logger('taxonomy')->notice('Deleted term %name.', array('%name' => $this->entity->getName())); } } diff --git a/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php b/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php index 8571464..0303c61 100644 --- a/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php +++ b/core/modules/taxonomy/src/Form/VocabularyDeleteForm.php @@ -47,17 +47,8 @@ public function getDescription() { /** * {@inheritdoc} */ - public function getDeletionMessage() { + protected function getDeletionMessage() { return $this->t('Deleted vocabulary %name.', array('%name' => $this->entity->label())); } - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - parent::submitForm($form, $form_state); - - $this->logger('taxonomy')->notice('Deleted vocabulary %name.', array('%name' => $this->entity->label())); - } - } diff --git a/core/modules/user/src/Form/UserRoleDelete.php b/core/modules/user/src/Form/UserRoleDelete.php index a4740cd..b974ce8 100644 --- a/core/modules/user/src/Form/UserRoleDelete.php +++ b/core/modules/user/src/Form/UserRoleDelete.php @@ -8,7 +8,6 @@ namespace Drupal\user\Form; use Drupal\Core\Entity\EntityDeleteForm; -use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** @@ -23,13 +22,4 @@ public function getCancelUrl() { return new Url('user.role_list'); } - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - parent::submitForm($form, $form_state); - - $this->logger('user')->notice('Role %name has been deleted.', array('%name' => $this->entity->label())); - } - }