ContentEntityDeleteForm.php in Zircon Profile 8
File
core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php
View source
<?php
namespace Drupal\Core\Entity;
use Drupal\Core\Form\FormStateInterface;
class ContentEntityDeleteForm extends ContentEntityConfirmFormBase {
use EntityDeleteFormTrait {
getQuestion as traitGetQuestion;
logDeletionMessage as traitLogDeletionMessage;
getDeletionMessage as traitGetDeletionMessage;
getCancelUrl as traitGetCancelUrl;
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$entity = $this
->getEntity();
if ($entity
->isDefaultTranslation()) {
if (count($entity
->getTranslationLanguages()) > 1) {
$languages = [];
foreach ($entity
->getTranslationLanguages() as $language) {
$languages[] = $language
->getName();
}
$form['deleted_translations'] = array(
'#theme' => 'item_list',
'#title' => $this
->t('The following @entity-type translations will be deleted:', [
'@entity-type' => $entity
->getEntityType()
->getLowercaseLabel(),
]),
'#items' => $languages,
);
$form['actions']['submit']['#value'] = $this
->t('Delete all translations');
}
}
else {
$form['actions']['submit']['#value'] = $this
->t('Delete @language translation', array(
'@language' => $entity
->language()
->getName(),
));
}
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$entity = $this
->getEntity();
if (!$entity
->isDefaultTranslation()) {
$untranslated_entity = $entity
->getUntranslated();
$untranslated_entity
->removeTranslation($entity
->language()
->getId());
$untranslated_entity
->save();
$form_state
->setRedirectUrl($untranslated_entity
->urlInfo('canonical'));
}
else {
$entity
->delete();
$form_state
->setRedirectUrl($this
->getRedirectUrl());
}
drupal_set_message($this
->getDeletionMessage());
$this
->logDeletionMessage();
}
public function getCancelUrl() {
$entity = $this
->getEntity();
return $entity
->isDefaultTranslation() ? $this
->traitGetCancelUrl() : $entity
->urlInfo('canonical');
}
protected function getDeletionMessage() {
$entity = $this
->getEntity();
if (!$entity
->isDefaultTranslation()) {
return $this
->t('The @entity-type %label @language translation has been deleted.', [
'@entity-type' => $entity
->getEntityType()
->getLowercaseLabel(),
'%label' => $entity
->label(),
'@language' => $entity
->language()
->getName(),
]);
}
return $this
->traitGetDeletionMessage();
}
protected function logDeletionMessage() {
$entity = $this
->getEntity();
if (!$entity
->isDefaultTranslation()) {
$this
->logger($entity
->getEntityType()
->getProvider())
->notice('The @entity-type %label @language translation has been deleted.', [
'@entity-type' => $entity
->getEntityType()
->getLowercaseLabel(),
'%label' => $entity
->label(),
'@language' => $entity
->language()
->getName(),
]);
}
else {
$this
->traitLogDeletionMessage();
}
}
public function getQuestion() {
$entity = $this
->getEntity();
if (!$entity
->isDefaultTranslation()) {
return $this
->t('Are you sure you want to delete the @language translation of the @entity-type %label?', array(
'@language' => $entity
->language()
->getName(),
'@entity-type' => $this
->getEntity()
->getEntityType()
->getLowercaseLabel(),
'%label' => $this
->getEntity()
->label(),
));
}
return $this
->traitGetQuestion();
}
}