diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/TermDelete.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/TermDelete.php new file mode 100644 index 0000000..4ca284d --- /dev/null +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/TermDelete.php @@ -0,0 +1,81 @@ + $this->term->label())); + } + + /** + * {@inheritdoc} + */ + protected function getCancelPath() { + return 'admin/structure/taxonomy'; + } + + /** + * {@inheritdoc} + */ + protected function getDescription() { + return t('Deleting a term will delete all its children if there are any. This action cannot be undone.'); + } + + /** + * {@inheritdoc} + */ + protected function getConfirmText() { + return t('Delete'); + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state, Term $taxonomy_term = NULL) { + $this->term = $taxonomy_term; + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + $this->term->delete(); + taxonomy_check_vocabulary_hierarchy(entity_load('taxonomy_vocabulary', $this->term->bundle()), array('tid' => $this->term->id())); + drupal_set_message(t('Deleted term %name.', array('%name' => $this->term->label()))); + watchdog('taxonomy', 'Deleted term %name.', array('%name' => $this->term->label()), WATCHDOG_NOTICE); + $form_state['redirect'] = 'admin/structure/taxonomy'; + Cache::invalidateTags(array('content' => TRUE)); + } + +} diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyDelete.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyDelete.php new file mode 100644 index 0000000..5db55c2 --- /dev/null +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyDelete.php @@ -0,0 +1,80 @@ + $this->vocabulary->label())); + } + + /** + * {@inheritdoc} + */ + protected function getCancelPath() { + return 'admin/structure/taxonomy'; + } + + /** + * {@inheritdoc} + */ + protected function getDescription() { + return t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'); + } + + /** + * {@inheritdoc} + */ + protected function getConfirmText() { + return t('Delete'); + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state, Vocabulary $taxonomy_vocabulary = NULL) { + $this->vocabulary = $taxonomy_vocabulary; + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + $this->vocabulary->delete(); + drupal_set_message(t('Deleted vocabulary %name.', array('%name' => $this->vocabulary->label()))); + watchdog('taxonomy', 'Deleted vocabulary %name.', array('%name' => $this->vocabulary->label()), WATCHDOG_NOTICE); + $form_state['redirect'] = 'admin/structure/taxonomy'; + Cache::invalidateTags(array('content' => TRUE)); + } + +} diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php index 6785335..0952eb3 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\taxonomy\VocabularyFormController. + * Contains \Drupal\taxonomy\VocabularyFormController. */ namespace Drupal\taxonomy; @@ -16,14 +16,10 @@ class VocabularyFormController extends EntityFormController { /** - * Overrides Drupal\Core\Entity\EntityFormController::form(). + * {@inheritdoc} */ public function form(array $form, array &$form_state, EntityInterface $vocabulary) { - // Check whether we need a deletion confirmation form. - if (isset($form_state['confirm_delete']) && isset($form_state['values']['vid'])) { - return taxonomy_vocabulary_confirm_delete($form, $form_state, $form_state['values']['vid']); - } $form['name'] = array( '#type' => 'textfield', '#title' => t('Name'), @@ -87,7 +83,6 @@ protected function actions(array $form, array &$form_state) { // If we are displaying the delete confirmation skip the regular actions. if (empty($form_state['confirm_delete'])) { $actions = parent::actions($form, $form_state); - array_unshift($actions['delete']['#submit'], array($this, 'submit')); // Add the language configuration submit handler. This is needed because // the submit button has custom submit handlers. if (module_exists('language')) { @@ -108,7 +103,7 @@ protected function actions(array $form, array &$form_state) { } /** - * Overrides Drupal\Core\Entity\EntityFormController::validate(). + * {@inheritdoc} */ public function validate(array $form, array &$form_state) { parent::validate($form, $form_state); @@ -144,24 +139,7 @@ public function languageConfigurationSubmit(array &$form, array &$form_state) { } /** - * Overrides Drupal\Core\Entity\EntityFormController::submit(). - */ - public function submit(array $form, array &$form_state) { - // @todo We should not be calling taxonomy_vocabulary_confirm_delete() from - // within the form builder. - if ($form_state['triggering_element']['#value'] == t('Delete')) { - // Rebuild the form to confirm vocabulary deletion. - $form_state['rebuild'] = TRUE; - $form_state['confirm_delete'] = TRUE; - return NULL; - } - else { - return parent::submit($form, $form_state); - } - } - - /** - * Overrides Drupal\Core\Entity\EntityFormController::save(). + * {@inheritdoc} */ public function save(array $form, array &$form_state) { $vocabulary = $this->getEntity($form_state); @@ -186,4 +164,13 @@ public function save(array $form, array &$form_state) { $form_state['values']['vid'] = $vocabulary->id(); $form_state['vid'] = $vocabulary->id(); } + + /** + * {@inheritdoc} + */ + public function delete(array $form, array &$form_state) { + $vocabulary = $this->getEntity($form_state); + $form_state['redirect'] = array('admin/structure/taxonomy/' . $vocabulary->id() . '/delete'); + } + } diff --git a/core/modules/taxonomy/taxonomy.admin.inc b/core/modules/taxonomy/taxonomy.admin.inc index d26501f..42134db 100644 --- a/core/modules/taxonomy/taxonomy.admin.inc +++ b/core/modules/taxonomy/taxonomy.admin.inc @@ -503,87 +503,6 @@ function taxonomy_term_add($vocabulary) { } /** - * Form builder for the term delete form. - * - * @ingroup forms - * @see taxonomy_term_confirm_delete_submit() - */ -function taxonomy_term_confirm_delete($form, &$form_state, Term $term) { - // Always provide entity id in the same form key as in the entity edit form. - $form['tid'] = array('#type' => 'value', '#value' => $term->tid); - - $form_state['taxonomy']['vocabulary'] = taxonomy_vocabulary_load($term->bundle());; - $form['type'] = array('#type' => 'value', '#value' => 'term'); - $form['name'] = array('#type' => 'value', '#value' => $term->name); - $form['vid'] = array('#type' => 'value', '#value' => $term->bundle()); - $form['delete'] = array('#type' => 'value', '#value' => TRUE); - return confirm_form($form, - t('Are you sure you want to delete the term %title?', - array('%title' => $term->label())), - 'admin/structure/taxonomy', - t('Deleting a term will delete all its children if there are any. This action cannot be undone.'), - t('Delete'), - t('Cancel')); -} - -/** - * Submit handler to delete a term after confirmation. - * - * @see taxonomy_term_confirm_delete() - */ -function taxonomy_term_confirm_delete_submit($form, &$form_state) { - taxonomy_term_delete($form_state['values']['tid']); - taxonomy_check_vocabulary_hierarchy($form_state['taxonomy']['vocabulary'], $form_state['values']); - drupal_set_message(t('Deleted term %name.', array('%name' => $form_state['values']['name']))); - watchdog('taxonomy', 'Deleted term %name.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE); - if (!isset($_GET['destination'])) { - $form_state['redirect'] = 'admin/structure/taxonomy'; - } - cache_invalidate_tags(array('content' => TRUE)); - return; -} - -/** - * Form builder for the vocabulary delete confirmation form. - * - * @ingroup forms - * @see taxonomy_vocabulary_confirm_delete_submit() - */ -function taxonomy_vocabulary_confirm_delete($form, &$form_state, $vid) { - $vocabulary = taxonomy_vocabulary_load($vid); - - // Always provide entity id in the same form key as in the entity edit form. - $form['vid'] = array('#type' => 'value', '#value' => $vid); - - $form_state['taxonomy']['vocabulary'] = $vocabulary; - $form['#id'] = 'taxonomy_vocabulary_confirm_delete'; - $form['type'] = array('#type' => 'value', '#value' => 'vocabulary'); - $form['name'] = array('#type' => 'value', '#value' => $vocabulary->name); - $form['#submit'] = array('taxonomy_vocabulary_confirm_delete_submit'); - return confirm_form($form, - t('Are you sure you want to delete the vocabulary %title?', - array('%title' => $vocabulary->label())), - 'admin/structure/taxonomy', - t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'), - t('Delete'), - t('Cancel')); -} - -/** - * Submit handler to delete a vocabulary after confirmation. - * - * @see taxonomy_vocabulary_confirm_delete() - */ -function taxonomy_vocabulary_confirm_delete_submit($form, &$form_state) { - $status = taxonomy_vocabulary_delete($form_state['values']['vid']); - drupal_set_message(t('Deleted vocabulary %name.', array('%name' => $form_state['values']['name']))); - watchdog('taxonomy', 'Deleted vocabulary %name.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE); - $form_state['redirect'] = 'admin/structure/taxonomy'; - cache_invalidate_tags(array('content' => TRUE)); - return; -} - -/** * Form builder to confirm resetting a vocabulary to alphabetical order. * * @ingroup forms diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 89f334b..daf5be2 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -298,13 +298,9 @@ function taxonomy_menu() { ); $items['taxonomy/term/%taxonomy_term/delete'] = array( 'title' => 'Delete', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('taxonomy_term_confirm_delete', 2), - 'access callback' => 'entity_page_access', - 'access arguments' => array(2, 'delete'), 'type' => MENU_LOCAL_TASK, 'weight' => 20, - 'file' => 'taxonomy.admin.inc', + 'route_name' => 'taxonomy_term_delete', ); $items['taxonomy/term/%taxonomy_term/feed'] = array( 'title' => 'Taxonomy term', @@ -348,6 +344,12 @@ function taxonomy_menu() { 'type' => MENU_LOCAL_TASK, 'file' => 'taxonomy.admin.inc', ); + $items['admin/structure/taxonomy/%taxonomy_vocabulary/delete'] = array( + 'title' => 'Delete', + 'type' => MENU_CONTEXT_INLINE, + 'weight' => 20, + 'route_name' => 'taxonomy_vocabulary_delete', + ); $items['admin/structure/taxonomy/%taxonomy_vocabulary/add'] = array( 'title' => 'Add term', diff --git a/core/modules/taxonomy/taxonomy.routing.yml b/core/modules/taxonomy/taxonomy.routing.yml new file mode 100644 index 0000000..d0cc261 --- /dev/null +++ b/core/modules/taxonomy/taxonomy.routing.yml @@ -0,0 +1,13 @@ +taxonomy_term_delete: + pattern: '/taxonomy/term/{taxonomy_term}/delete' + defaults: + _form: '\Drupal\taxonomy\Form\TermDelete' + requirements: + _entity_access: 'taxonomy_term.delete' + +taxonomy_vocabulary_delete: + pattern: '/admin/structure/taxonomy/{taxonomy_vocabulary}/delete' + defaults: + _form: '\Drupal\taxonomy\Form\VocabularyDelete' + requirements: + _entity_access: 'taxonomy_vocabulary.delete'