Pull merge.
[yaffs-website] / web / core / modules / taxonomy / src / Form / VocabularyResetForm.php
1 <?php
2
3 namespace Drupal\taxonomy\Form;
4
5 use Drupal\Core\Entity\EntityConfirmFormBase;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\taxonomy\TermStorageInterface;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
9
10 /**
11  * Provides confirmation form for resetting a vocabulary to alphabetical order.
12  *
13  * @internal
14  */
15 class VocabularyResetForm extends EntityConfirmFormBase {
16
17   /**
18    * The term storage.
19    *
20    * @var \Drupal\taxonomy\TermStorageInterface
21    */
22   protected $termStorage;
23
24   /**
25    * Constructs a new VocabularyResetForm object.
26    *
27    * @param \Drupal\taxonomy\TermStorageInterface $term_storage
28    *   The term storage.
29    */
30   public function __construct(TermStorageInterface $term_storage) {
31     $this->termStorage = $term_storage;
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   public static function create(ContainerInterface $container) {
38     return new static(
39       $container->get('entity.manager')->getStorage('taxonomy_term')
40     );
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function getFormId() {
47     return 'taxonomy_vocabulary_confirm_reset_alphabetical';
48   }
49
50   /**
51    * {@inheritdoc}
52    */
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()]);
55   }
56
57   /**
58    * {@inheritdoc}
59    */
60   public function getCancelUrl() {
61     return $this->entity->urlInfo('overview-form');
62   }
63
64   /**
65    * {@inheritdoc}
66    */
67   public function getDescription() {
68     return $this->t('Resetting a vocabulary will discard all custom ordering and sort items alphabetically.');
69   }
70
71   /**
72    * {@inheritdoc}
73    */
74   public function getConfirmText() {
75     return $this->t('Reset to alphabetical');
76   }
77
78   /**
79    * {@inheritdoc}
80    */
81   public function submitForm(array &$form, FormStateInterface $form_state) {
82     parent::submitForm($form, $form_state);
83     $this->termStorage->resetWeights($this->entity->id());
84
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());
88   }
89
90 }