public function HostDeleteForm::submitForm in http:BL 8
Delete the entity and log the event. logger() replaces the watchdog.
Overrides ContentEntityForm::submitForm
File
- src/
Form/ HostDeleteForm.php, line 118
Class
- HostDeleteForm
- Provides a form for deleting (and unbanning) a host entity.
Namespace
Drupal\httpbl\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$entity = $this
->getEntity();
if ($this->banManager
->isBanned($entity->host_ip->value)) {
$this->banManager
->unbanIp($entity->host_ip->value);
$unbanned = TRUE;
}
else {
$unbanned = FALSE;
}
//Delete the host.
$entity
->delete();
$user = $this
->currentUser();
$user = $user
->getDisplayName();
if ($unbanned) {
$this->logTrapper
->trapNotice('@type deleted and unbanned: @title, by user @user. Source: @source.', array(
'@type' => $this->entity
->bundle(),
'@title' => $this->entity
->label(),
'@user' => $user,
'@source' => $this->entity
->getSource(),
'link' => $this->entity
->projectLink(),
));
drupal_set_message($this
->t('Evaluated host @ip was deleted and unbanned.', array(
'@ip' => $entity->host_ip->value,
)));
}
else {
$this->logTrapper
->trapNotice('@type deleted: @title, by user @user. Source: @source.', array(
'@type' => $this->entity
->bundle(),
'@title' => $this->entity
->label(),
'@user' => $user,
'@source' => $this->entity
->getSource(),
'link' => $this->entity
->projectLink(),
));
drupal_set_message($this
->t('Evaluated host @ip was deleted.', array(
'@ip' => $entity->host_ip->value,
)));
}
$form_state
->setRedirect('entity.host.collection');
}