e036ff91768a8b77fa1a37025069e4126dc6c01d
[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 class VocabularyResetForm extends EntityConfirmFormBase {
14
15   /**
16    * The term storage.
17    *
18    * @var \Drupal\taxonomy\TermStorageInterface
19    */
20   protected $termStorage;
21
22   /**
23    * Constructs a new VocabularyResetForm object.
24    *
25    * @param \Drupal\taxonomy\TermStorageInterface $term_storage
26    *   The term storage.
27    */
28   public function __construct(TermStorageInterface $term_storage) {
29     $this->termStorage = $term_storage;
30   }
31
32   /**
33    * {@inheritdoc}
34    */
35   public static function create(ContainerInterface $container) {
36     return new static(
37       $container->get('entity.manager')->getStorage('taxonomy_term')
38     );
39   }
40
41   /**
42    * {@inheritdoc}
43    */
44   public function getFormId() {
45     return 'taxonomy_vocabulary_confirm_reset_alphabetical';
46   }
47
48   /**
49    * {@inheritdoc}
50    */
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()]);
53   }
54
55   /**
56    * {@inheritdoc}
57    */
58   public function getCancelUrl() {
59     return $this->entity->urlInfo('overview-form');
60   }
61
62   /**
63    * {@inheritdoc}
64    */
65   public function getDescription() {
66     return $this->t('Resetting a vocabulary will discard all custom ordering and sort items alphabetically.');
67   }
68
69   /**
70    * {@inheritdoc}
71    */
72   public function getConfirmText() {
73     return $this->t('Reset to alphabetical');
74   }
75
76   /**
77    * {@inheritdoc}
78    */
79   public function submitForm(array &$form, FormStateInterface $form_state) {
80     parent::submitForm($form, $form_state);
81     $this->termStorage->resetWeights($this->entity->id());
82
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());
86   }
87
88 }