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..c8c160e --- /dev/null +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/TermDelete.php @@ -0,0 +1,115 @@ +storageController = $storage_controller; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('plugin.manager.entity')->getStorageController('taxonomy_vocabulary') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'taxonomy_term_confirm_delete'; + } + + /** + * {@inheritdoc} + */ + protected function getQuestion() { + return t('Are you sure you want to delete the term %title?', array('%title' => $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} + * + * @param \Drupal\taxonomy\TermInterface $taxonomy_term + * The taxonomy term to delete. + */ + public function buildForm(array $form, array &$form_state, TermInterface $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(); + $vocabulary = $this->storageController->load(array($this->term->bundle())); + // @todo Move to storage controller http://drupal.org/node/1988712 + taxonomy_check_vocabulary_hierarchy(reset($vocabulary), 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..9aeb127 --- /dev/null +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyDelete.php @@ -0,0 +1,83 @@ + $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} + * + * @param \Drupal\taxonomy\VocabularyInterface $taxonomy_vocabulary + * The taxonomy vocabulary to delete. + */ + public function buildForm(array $form, array &$form_state, VocabularyInterface $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/TermInterface.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermInterface.php index 20169e8..f9bb432 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermInterface.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermInterface.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\taxonomy\Plugin\Core\Entity\TermInterface. + * Contains \Drupal\taxonomy\TermInterface. */ namespace Drupal\taxonomy; diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php index 96e8697..9907756 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; @@ -15,15 +15,11 @@ class VocabularyFormController extends EntityFormController { /** - * Overrides Drupal\Core\Entity\EntityFormController::form(). + * {@inheritdoc} */ public function form(array $form, array &$form_state) { $vocabulary = $this->entity; - // 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')) { @@ -124,24 +119,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->entity; @@ -166,4 +144,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/manage/' . $vocabulary->id() . '/delete'); + } + } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyInterface.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyInterface.php index 51ec34f..80c7781 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyInterface.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyInterface.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\taxonomy\Plugin\Core\Entity\VocabularyInterface. + * Contains \Drupal\taxonomy\VocabularyInterface. */ namespace Drupal\taxonomy; diff --git a/core/modules/taxonomy/taxonomy.admin.inc b/core/modules/taxonomy/taxonomy.admin.inc index 0703071..72a7600 100644 --- a/core/modules/taxonomy/taxonomy.admin.inc +++ b/core/modules/taxonomy/taxonomy.admin.inc @@ -484,87 +484,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->id()); - - $form_state['taxonomy']['vocabulary'] = taxonomy_vocabulary_load($term->bundle()); - $form['type'] = array('#type' => 'value', '#value' => 'term'); - $form['name'] = array('#type' => 'value', '#value' => $term->label()); - $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) { - entity_delete_multiple('taxonomy_term', array($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) { - $form_state['taxonomy']['vocabulary']->delete(); - 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 2557008..de60ac5 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -5,6 +5,7 @@ * Enables the organization of content into categories. */ +use Drupal\taxonomy\VocabularyInterface; use Drupal\node\Plugin\Core\Entity\Node; use Drupal\taxonomy\Plugin\Core\Entity\Term; use Drupal\taxonomy\Plugin\Core\Entity\Vocabulary; @@ -279,14 +280,10 @@ 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, 'context' => MENU_CONTEXT_INLINE, 'weight' => 20, - 'file' => 'taxonomy.admin.inc', + 'route_name' => 'taxonomy_term_delete', ); $items['taxonomy/term/%taxonomy_term/feed'] = array( 'title' => 'Taxonomy term', @@ -330,6 +327,13 @@ function taxonomy_menu() { 'type' => MENU_LOCAL_TASK, 'file' => 'taxonomy.admin.inc', ); + $items['admin/structure/taxonomy/%taxonomy_vocabulary/delete'] = array( + 'title' => 'Delete', + 'type' => MENU_LOCAL_TASK, + 'context' => MENU_CONTEXT_INLINE, + 'weight' => 20, + 'route_name' => 'taxonomy_vocabulary_delete', + ); $items['admin/structure/taxonomy/manage/%taxonomy_vocabulary/add'] = array( 'title' => 'Add term', @@ -381,7 +385,7 @@ function taxonomy_admin_paths() { * term has multiple parents then the vocabulary will be given a hierarchy of * TAXONOMY_HIERARCHY_MULTIPLE. * - * @param Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary + * @param \Drupal\taxonomy\VocabularyInterface $vocabulary * A taxonomy vocabulary entity. * @param $changed_term * An array of the term structure that was updated. @@ -389,7 +393,7 @@ function taxonomy_admin_paths() { * @return * An integer that represents the level of the vocabulary's hierarchy. */ -function taxonomy_check_vocabulary_hierarchy(Vocabulary $vocabulary, $changed_term) { +function taxonomy_check_vocabulary_hierarchy(VocabularyInterface $vocabulary, $changed_term) { $tree = taxonomy_get_tree($vocabulary->id()); $hierarchy = TAXONOMY_HIERARCHY_DISABLED; foreach ($tree as $term) { diff --git a/core/modules/taxonomy/taxonomy.routing.yml b/core/modules/taxonomy/taxonomy.routing.yml new file mode 100644 index 0000000..5ee66fc --- /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/manage/{taxonomy_vocabulary}/delete' + defaults: + _form: '\Drupal\taxonomy\Form\VocabularyDelete' + requirements: + _entity_access: 'taxonomy_vocabulary.delete'