3 namespace Drupal\taxonomy\Form;
5 use Drupal\Core\Entity\EntityConfirmFormBase;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\taxonomy\TermStorageInterface;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
11 * Provides confirmation form for resetting a vocabulary to alphabetical order.
13 class VocabularyResetForm extends EntityConfirmFormBase {
18 * @var \Drupal\taxonomy\TermStorageInterface
20 protected $termStorage;
23 * Constructs a new VocabularyResetForm object.
25 * @param \Drupal\taxonomy\TermStorageInterface $term_storage
28 public function __construct(TermStorageInterface $term_storage) {
29 $this->termStorage = $term_storage;
35 public static function create(ContainerInterface $container) {
37 $container->get('entity.manager')->getStorage('taxonomy_term')
44 public function getFormId() {
45 return 'taxonomy_vocabulary_confirm_reset_alphabetical';
51 public function getQuestion() {
52 return $this->t('Are you sure you want to reset the vocabulary %title to alphabetical order?', ['%title' => $this->entity->label()]);
58 public function getCancelUrl() {
59 return $this->entity->urlInfo('overview-form');
65 public function getDescription() {
66 return $this->t('Resetting a vocabulary will discard all custom ordering and sort items alphabetically.');
72 public function getConfirmText() {
73 return $this->t('Reset to alphabetical');
79 public function submitForm(array &$form, FormStateInterface $form_state) {
80 parent::submitForm($form, $form_state);
81 $this->termStorage->resetWeights($this->entity->id());
83 drupal_set_message($this->t('Reset vocabulary %name to alphabetical order.', ['%name' => $this->entity->label()]));
84 $this->logger('taxonomy')->notice('Reset vocabulary %name to alphabetical order.', ['%name' => $this->entity->label()]);
85 $form_state->setRedirectUrl($this->getCancelUrl());