diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyReset.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyReset.php new file mode 100644 index 0000000..bf6ee64 --- /dev/null +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyReset.php @@ -0,0 +1,113 @@ +database = $database; + + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('database') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'taxonomy_vocabulary_confirm_reset_alphabetical'; + } + + /** + * {@inheritdoc} + */ + public function getQuestion() { + return t('Are you sure you want to reset the vocabulary %title to alphabetical order?', array('%title' => $this->vocabulary->label())); + } + + /** + * {@inheritdoc} + */ + public function getCancelPath() { + return 'admin/structure/taxonomy/manage/' . $this->vocabulary->id(); + } + + /** + * {@inheritdoc} + */ + public function getDescription() { + return t('Resetting a vocabulary will discard all custom ordering and sort items alphabetically.'); + } + + /** + * {@inheritdoc} + */ + public function getConfirmText() { + return t('Reset to alphabetical'); + } + + /** + * {@inheritdoc} + * + * @param \Drupal\taxonomy\VocabularyInterface $taxonomy_vocabulary + * The taxonomy vocabulary to reset. + */ + 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->database->update('taxonomy_term_data') + ->fields(array('weight' => 0)) + ->condition('vid', $this->vocabulary->id()) + ->execute(); + + drupal_set_message(t('Reset vocabulary %name to alphabetical order.', array('%name' => $this->vocabulary->label()))); + watchdog('taxonomy', 'Reset vocabulary %name to alphabetical order.', array('%name' => $this->vocabulary->label()), WATCHDOG_NOTICE); + $form_state['redirect'] = 'admin/structure/taxonomy/manage/' . $this->vocabulary->id(); + } + +} diff --git a/core/modules/taxonomy/taxonomy.admin.inc b/core/modules/taxonomy/taxonomy.admin.inc index 153bbaf..43ad4b5 100644 --- a/core/modules/taxonomy/taxonomy.admin.inc +++ b/core/modules/taxonomy/taxonomy.admin.inc @@ -36,11 +36,6 @@ function taxonomy_vocabulary_add() { function taxonomy_overview_terms($form, &$form_state, Vocabulary $vocabulary) { global $pager_page_array, $pager_total, $pager_total_items; - // Check for confirmation forms. - if (isset($form_state['confirm_reset_alphabetical'])) { - return taxonomy_vocabulary_confirm_reset_alphabetical($form, $form_state, $vocabulary->id()); - } - $form_state['taxonomy']['vocabulary'] = $vocabulary; $parent_fields = FALSE; @@ -308,13 +303,8 @@ function taxonomy_overview_terms($form, &$form_state, Vocabulary $vocabulary) { */ function taxonomy_overview_terms_submit($form, &$form_state) { if ($form_state['triggering_element']['#value'] == t('Reset to alphabetical')) { - // Execute the reset action. - if ($form_state['values']['reset_alphabetical'] === TRUE) { - return taxonomy_vocabulary_confirm_reset_alphabetical_submit($form, $form_state); - } - // Rebuild the form to confirm the reset action. - $form_state['rebuild'] = TRUE; - $form_state['confirm_reset_alphabetical'] = TRUE; + // Redirect to confirmation form for the reset action. + $form_state['redirect'] = 'admin/structure/taxonomy/manage/' . $form_state['taxonomy']['vocabulary']->id() . '/reset'; return; } @@ -396,40 +386,3 @@ function taxonomy_overview_terms_submit($form, &$form_state) { } drupal_set_message(t('The configuration options have been saved.')); } - -/** - * Form builder to confirm resetting a vocabulary to alphabetical order. - * - * @ingroup forms - * @see taxonomy_vocabulary_confirm_reset_alphabetical_submit() - */ -function taxonomy_vocabulary_confirm_reset_alphabetical($form, &$form_state, $vid) { - $vocabulary = taxonomy_vocabulary_load($vid); - - $form['type'] = array('#type' => 'value', '#value' => 'vocabulary'); - $form['vid'] = array('#type' => 'value', '#value' => $vid); - $form['name'] = array('#type' => 'value', '#value' => $vocabulary->name); - $form['reset_alphabetical'] = array('#type' => 'value', '#value' => TRUE); - return confirm_form($form, - t('Are you sure you want to reset the vocabulary %title to alphabetical order?', - array('%title' => $vocabulary->label())), - 'admin/structure/taxonomy/manage/' . $vocabulary->id(), - t('Resetting a vocabulary will discard all custom ordering and sort items alphabetically.'), - t('Reset to alphabetical'), - t('Cancel')); -} - -/** - * Submit handler to reset a vocabulary to alphabetical order after confirmation. - * - * @see taxonomy_vocabulary_confirm_reset_alphabetical() - */ -function taxonomy_vocabulary_confirm_reset_alphabetical_submit($form, &$form_state) { - db_update('taxonomy_term_data') - ->fields(array('weight' => 0)) - ->condition('vid', $form_state['values']['vid']) - ->execute(); - drupal_set_message(t('Reset vocabulary %name to alphabetical order.', array('%name' => $form_state['values']['name']))); - watchdog('taxonomy', 'Reset vocabulary %name to alphabetical order.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE); - $form_state['redirect'] = 'admin/structure/taxonomy/manage/' . $form_state['values']['vid']; -} diff --git a/core/modules/taxonomy/taxonomy.routing.yml b/core/modules/taxonomy/taxonomy.routing.yml index 6aeed3e..3bd4b0f 100644 --- a/core/modules/taxonomy/taxonomy.routing.yml +++ b/core/modules/taxonomy/taxonomy.routing.yml @@ -25,3 +25,10 @@ taxonomy_vocabulary_delete: _entity_form: 'taxonomy_vocabulary.delete' requirements: _entity_access: 'taxonomy_vocabulary.delete' + +taxonomy_vocabulary_reset: + pattern: '/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/reset' + defaults: + _form: '\Drupal\taxonomy\Form\VocabularyReset' + requirements: + _entity_access: 'taxonomy_vocabulary.view'