diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyResetForm.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyResetForm.php new file mode 100644 index 0000000..4366cb2 --- /dev/null +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyResetForm.php @@ -0,0 +1,97 @@ +connection = $connection; + } + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { + return new static( + $container->get('module_handler'), + $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->entity->label())); + } + + /** + * {@inheritdoc} + */ + public function getCancelPath() { + return 'admin/structure/taxonomy/manage/' . $this->entity->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} + */ + public function save(array $form, array &$form_state) { + $this->connection->update('taxonomy_term_data') + ->fields(array('weight' => 0)) + ->condition('vid', $this->entity->id()) + ->execute(); + + drupal_set_message(t('Reset vocabulary %name to alphabetical order.', array('%name' => $this->entity->label()))); + watchdog('taxonomy', 'Reset vocabulary %name to alphabetical order.', array('%name' => $this->entity->label()), WATCHDOG_NOTICE); + $form_state['redirect'] = 'admin/structure/taxonomy/manage/' . $this->entity->id(); + } + +} diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Vocabulary.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Vocabulary.php index ea9eda6..abcb75b 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Vocabulary.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Vocabulary.php @@ -26,6 +26,7 @@ * "list" = "Drupal\taxonomy\VocabularyListController", * "form" = { * "default" = "Drupal\taxonomy\VocabularyFormController", + * "reset" = "Drupal\taxonomy\Form\VocabularyResetForm", * "delete" = "Drupal\taxonomy\Form\VocabularyDeleteForm" * } * }, diff --git a/core/modules/taxonomy/taxonomy.admin.inc b/core/modules/taxonomy/taxonomy.admin.inc index 153bbaf..876c49c 100644 --- a/core/modules/taxonomy/taxonomy.admin.inc +++ b/core/modules/taxonomy/taxonomy.admin.inc @@ -5,7 +5,6 @@ * Administrative page callbacks for the taxonomy module. */ -use Drupal\taxonomy\Plugin\Core\Entity\Term; use Drupal\taxonomy\Plugin\Core\Entity\Vocabulary; /** @@ -36,11 +35,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 +302,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 +385,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..09dc6d0 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: + _entity_form: 'taxonomy_vocabulary.reset' + requirements: + _permission: 'administer taxonomy'