0e97ff64a4b0a4cba75a6bf87d943dfbcddfbd90
[yaffs-website] / web / core / modules / taxonomy / src / Form / TermDeleteForm.php
1 <?php
2
3 namespace Drupal\taxonomy\Form;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\Core\Entity\ContentEntityDeleteForm;
7 use Drupal\Core\Url;
8
9 /**
10  * Provides a deletion confirmation form for taxonomy term.
11  */
12 class TermDeleteForm extends ContentEntityDeleteForm {
13
14   /**
15    * {@inheritdoc}
16    */
17   public function getCancelUrl() {
18     // The cancel URL is the vocabulary collection, terms have no global
19     // list page.
20     return new Url('entity.taxonomy_vocabulary.collection');
21   }
22
23   /**
24    * {@inheritdoc}
25    */
26   protected function getRedirectUrl() {
27     return $this->getCancelUrl();
28   }
29
30   /**
31    * {@inheritdoc}
32    */
33   public function getDescription() {
34     return $this->t('Deleting a term will delete all its children if there are any. This action cannot be undone.');
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   protected function getDeletionMessage() {
41     return $this->t('Deleted term %name.', ['%name' => $this->entity->label()]);
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public function submitForm(array &$form, FormStateInterface $form_state) {
48     parent::submitForm($form, $form_state);
49
50     /** @var \Drupal\Core\Entity\ContentEntityInterface $term */
51     $term = $this->getEntity();
52     if ($term->isDefaultTranslation()) {
53       $storage = $this->entityManager->getStorage('taxonomy_vocabulary');
54       $vocabulary = $storage->load($this->entity->bundle());
55
56       // @todo Move to storage http://drupal.org/node/1988712
57       taxonomy_check_vocabulary_hierarchy($vocabulary, ['tid' => $term->id()]);
58     }
59   }
60
61 }