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.
15 class VocabularyResetForm extends EntityConfirmFormBase {
20 * @var \Drupal\taxonomy\TermStorageInterface
22 protected $termStorage;
25 * Constructs a new VocabularyResetForm object.
27 * @param \Drupal\taxonomy\TermStorageInterface $term_storage
30 public function __construct(TermStorageInterface $term_storage) {
31 $this->termStorage = $term_storage;
37 public static function create(ContainerInterface $container) {
39 $container->get('entity.manager')->getStorage('taxonomy_term')
46 public function getFormId() {
47 return 'taxonomy_vocabulary_confirm_reset_alphabetical';
53 public function getQuestion() {
54 return $this->t('Are you sure you want to reset the vocabulary %title to alphabetical order?', ['%title' => $this->entity->label()]);
60 public function getCancelUrl() {
61 return $this->entity->urlInfo('overview-form');
67 public function getDescription() {
68 return $this->t('Resetting a vocabulary will discard all custom ordering and sort items alphabetically.');
74 public function getConfirmText() {
75 return $this->t('Reset to alphabetical');
81 public function submitForm(array &$form, FormStateInterface $form_state) {
82 parent::submitForm($form, $form_state);
83 $this->termStorage->resetWeights($this->entity->id());
85 $this->messenger()->addStatus($this->t('Reset vocabulary %name to alphabetical order.', ['%name' => $this->entity->label()]));
86 $this->logger('taxonomy')->notice('Reset vocabulary %name to alphabetical order.', ['%name' => $this->entity->label()]);
87 $form_state->setRedirectUrl($this->getCancelUrl());