CustomLanguageDeleteForm.php in Custom Language field 8
File
src/Form/CustomLanguageDeleteForm.php
View source
<?php
namespace Drupal\languagefield\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class CustomLanguageDeleteForm extends EntityConfirmFormBase {
public function getQuestion() {
return $this
->t('Are you sure you want to delete the language %name?', [
'%name' => $this->entity
->label(),
]);
}
public function getCancelUrl() {
return new Url('languagefield.custom_language.collection');
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity
->delete();
$this
->logger('languagefield')
->notice('The language %name has been deleted.', [
'%name' => $this->entity
->label(),
]);
$this
->messenger()
->addStatus($this
->t('The language %name has been deleted.', [
'%name' => $this->entity
->label(),
]));
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
}