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