ContentTranslationDeleteForm.php 1.95 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
<?php

/**
 * @file
 * Contains \Drupal\content_translation\Form\ContentTranslationDeleteForm.
 */

namespace Drupal\content_translation\Form;

use Drupal\Core\Form\ConfirmFormBase;
11
use Drupal\Core\Form\FormStateInterface;
12
use Drupal\Core\Language\LanguageInterface;
13
use Drupal\Core\Url;
14
15

/**
16
 * Delete translation form for content_translation module.
17
18
19
20
21
22
23
24
25
26
27
28
29
 */
class ContentTranslationDeleteForm extends ConfirmFormBase {

  /**
   * The entity whose translation is being deleted.
   *
   * @var \Drupal\Core\Entity\EntityInterface
   */
  protected $entity;

  /**
   * The language of the translation being deleted.
   *
30
   * @var \Drupal\Core\Language\LanguageInterface
31
32
33
34
35
36
37
38
39
40
41
42
43
   */
  protected $language;

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'content_translation_delete_confirm';
  }

  /**
   * {@inheritdoc}
   */
44
45
46
  public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, LanguageInterface $language = NULL) {
    $this->entity = $this->getRouteMatch()->getParameter($entity_type_id);
    $this->language = $language;
47
48
49
50
51
52
53
54
55
56
57
58
59
60
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function getConfirmText() {
    return $this->t('Delete');
  }

  /**
   * {@inheritdoc}
   */
  public function getQuestion() {
61
    return $this->t('Are you sure you want to delete the @language translation of %label?', array('@language' => $this->language->getName(), '%label' => $this->entity->label()));
62
63
64
65
66
  }

  /**
   * {@inheritdoc}
   */
67
  public function getCancelUrl() {
68
    return $this->entity->urlInfo('drupal:content-translation-overview');
69
70
71
72
73
  }

  /**
   * {@inheritdoc}
   */
74
  public function submitForm(array &$form, FormStateInterface $form_state) {
75
    // Remove the translated values.
76
    $this->entity = $this->entity->getUntranslated();
77
    $this->entity->removeTranslation($this->language->getId());
78
79
    $this->entity->save();

80
    $form_state->setRedirectUrl($this->getCancelUrl());
81
82
83
  }

}