diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Access/TermDeleteAccessCheck.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Access/TermDeleteAccessCheck.php new file mode 100644 index 0000000..a81a515 --- /dev/null +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Access/TermDeleteAccessCheck.php @@ -0,0 +1,36 @@ +getRequirements()); + } + + /** + * Implements AccessCheckInterface::access(). + */ + public function access(Route $route, Request $request) { + if ($entity = $request->attributes->get('taxonomy_term')) { + return $entity->access('delete'); + } + return FALSE; + } + +} diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Access/VocabularyDeleteAccessCheck.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Access/VocabularyDeleteAccessCheck.php new file mode 100644 index 0000000..e9563f2 --- /dev/null +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Access/VocabularyDeleteAccessCheck.php @@ -0,0 +1,36 @@ +getRequirements()); + } + + /** + * Implements AccessCheckInterface::access(). + */ + public function access(Route $route, Request $request) { + if ($entity = $request->attributes->get('taxonomy_vocabulary')) { + return $entity->access('delete'); + } + return FALSE; + } + +} 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..f214adc --- /dev/null +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/TermDelete.php @@ -0,0 +1,81 @@ + $this->taxonomy_term->label())); + } + + /** + * Implements \Drupal\Core\Form\ConfirmFormBase::getCancelPath(). + */ + protected function getCancelPath() { + return 'admin/structure/taxonomy'; + } + + /** + * Overrides \Drupal\Core\Form\ConfirmFormBase::getDescription(). + */ + protected function getDescription() { + return t('Deleting a term will delete all its children if there are any. This action cannot be undone.'); + } + + /** + * Overrides \Drupal\Core\Form\ConfirmFormBase::getConfirmText(). + */ + protected function getConfirmText() { + return t('Delete'); + } + + /** + * Overrides \Drupal\Core\Form\ConfirmFormBase::buildForm(). + */ + public function buildForm(array $form, array &$form_state, Term $taxonomy_term = NULL) { + $this->taxonomy_term = $taxonomy_term; + return parent::buildForm($form, $form_state); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::submitForm(). + */ + public function submitForm(array &$form, array &$form_state) { + $this->taxonomy_term->delete(); + taxonomy_check_vocabulary_hierarchy(entity_load('taxonomy_vocabulary', $this->taxonomy_term->bundle()), array('tid' => $this->taxonomy_term->id())); + drupal_set_message(t('Deleted term %name.', array('%name' => $this->taxonomy_term->label()))); + watchdog('taxonomy', 'Deleted term %name.', array('%name' => $this->taxonomy_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..6f0d16a --- /dev/null +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyDelete.php @@ -0,0 +1,80 @@ + $this->taxonomy_vocabulary->label())); + } + + /** + * Implements \Drupal\Core\Form\ConfirmFormBase::getCancelPath(). + */ + protected function getCancelPath() { + return 'admin/structure/taxonomy'; + } + + /** + * Overrides \Drupal\Core\Form\ConfirmFormBase::getDescription(). + */ + protected function getDescription() { + return t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'); + } + + /** + * Overrides \Drupal\Core\Form\ConfirmFormBase::getConfirmText(). + */ + protected function getConfirmText() { + return t('Delete'); + } + + /** + * Overrides \Drupal\Core\Form\ConfirmFormBase::buildForm(). + */ + public function buildForm(array $form, array &$form_state, Vocabulary $taxonomy_vocabulary = NULL) { + $this->taxonomy_vocabulary = $taxonomy_vocabulary; + return parent::buildForm($form, $form_state); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::submitForm(). + */ + public function submitForm(array &$form, array &$form_state) { + $this->taxonomy_vocabulary->delete(); + drupal_set_message(t('Deleted vocabulary %name.', array('%name' => $this->taxonomy_vocabulary->label()))); + watchdog('taxonomy', 'Deleted vocabulary %name.', array('%name' => $this->taxonomy_vocabulary->label()), WATCHDOG_NOTICE); + $form_state['redirect'] = 'admin/structure/taxonomy'; + Cache::invalidateTags(array('content' => TRUE)); + } + +} diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TaxonomyBundle.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TaxonomyBundle.php new file mode 100644 index 0000000..4611e61 --- /dev/null +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TaxonomyBundle.php @@ -0,0 +1,28 @@ +register('access_check.taxonomy.term', 'Drupal\taxonomy\Access\TermDeleteAccessCheck') + ->addTag('access_check'); + $container->register('access_check.taxonomy.term', 'Drupal\taxonomy\Access\VocabularyDeleteAccessCheck') + ->addTag('access_check'); + } + +} diff --git a/core/modules/taxonomy/taxonomy.admin.inc b/core/modules/taxonomy/taxonomy.admin.inc index 6305e48..5747ae0 100644 --- a/core/modules/taxonomy/taxonomy.admin.inc +++ b/core/modules/taxonomy/taxonomy.admin.inc @@ -548,87 +548,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 43d2ac8..7958760 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -304,13 +304,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', @@ -354,6 +350,12 @@ 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, + '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..1439e2f --- /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: + _access_taxonomy_term_delete: 'TRUE' + +taxonomy_vocabulary_delete: + pattern: '/admin/structure/taxonomy/{taxonomy_vocabulary}/delete' + defaults: + _form: '\Drupal\taxonomy\Form\VocabularyDelete' + requirements: + _access_taxonomy_vocabulary_delete: 'TRUE'