Newer
Older
Angie Byron
committed
<?php
/**
* @file
* Contains \Drupal\content_translation\Form\ContentTranslationDeleteForm.
*/
namespace Drupal\content_translation\Form;
use Drupal\Core\Form\ConfirmFormBase;
Dries Buytaert
committed
use Drupal\Core\Form\FormStateInterface;
Angie Byron
committed
use Drupal\Core\Url;
Angie Byron
committed
/**
Alex Pott
committed
* Delete translation form for content_translation module.
Angie Byron
committed
*/
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.
*
* @var \Drupal\Core\Language\LanguageInterface
Angie Byron
committed
*/
protected $language;
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'content_translation_delete_confirm';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $language = NULL) {
$this->entity = $this->getRequest()->attributes->get($entity_type_id);
Angie Byron
committed
$this->language = language_load($language);
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Delete');
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete the @language translation of %label?', array('@language' => $this->language->name, '%label' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
Angie Byron
committed
return $this->entity->urlInfo('drupal:content-translation-overview');
Angie Byron
committed
}
/**
* {@inheritdoc}
*/
Dries Buytaert
committed
public function submitForm(array &$form, FormStateInterface $form_state) {
Angie Byron
committed
// Remove the translated values.
$this->entity->removeTranslation($this->language->id);
$this->entity->save();
// Remove any existing path alias for the removed translation.
// @todo This should be taken care of by the Path module.
if (\Drupal::moduleHandler()->moduleExists('path')) {
Alex Pott
committed
$path = $this->entity->getSystemPath();
$conditions = array('source' => $path, 'langcode' => $this->language->id);
Alex Pott
committed
\Drupal::service('path.alias_storage')->delete($conditions);
Angie Byron
committed
}
Alex Pott
committed
$form_state->setRedirectUrl($this->getCancelUrl());