Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 72 |
ContentEntityDeleteForm | |
0.00% |
0 / 1 |
|
0.00% |
0 / 6 |
210 | |
0.00% |
0 / 72 |
buildForm | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 23 |
|||
submitForm | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 14 |
|||
getCancelUrl | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 3 |
|||
getDeletionMessage | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 10 |
|||
logDeletionMessage | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 12 |
|||
getQuestion | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 10 |
<?php | |
/** | |
* @file | |
* Contains \Drupal\Core\Entity\ContentEntityDeleteForm. | |
*/ | |
namespace Drupal\Core\Entity; | |
use Drupal\Core\Form\FormStateInterface; | |
/** | |
* Provides a generic base class for a content entity deletion form. | |
* | |
* @todo Re-evaluate and streamline the entity deletion form class hierarchy in | |
* https://www.drupal.org/node/2491057. | |
*/ | |
class ContentEntityDeleteForm extends ContentEntityConfirmFormBase { | |
use EntityDeleteFormTrait { | |
getQuestion as traitGetQuestion; | |
logDeletionMessage as traitLogDeletionMessage; | |
getDeletionMessage as traitGetDeletionMessage; | |
getCancelUrl as traitGetCancelUrl; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function buildForm(array $form, FormStateInterface $form_state) { | |
$form = parent::buildForm($form, $form_state); | |
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ | |
$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; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function submitForm(array &$form, FormStateInterface $form_state) { | |
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ | |
$entity = $this->getEntity(); | |
// Make sure that deleting a translation does not delete the whole entity. | |
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(); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getCancelUrl() { | |
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ | |
$entity = $this->getEntity(); | |
return $entity->isDefaultTranslation() ? $this->traitGetCancelUrl() : $entity->urlInfo('canonical'); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function getDeletionMessage() { | |
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ | |
$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(); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function logDeletionMessage() { | |
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ | |
$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(); | |
} | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getQuestion() { | |
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ | |
$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(); | |
} | |
} |