BrokenLinkDeleteForm.php in Broken Link 8.2
File
src/Form/BrokenLinkDeleteForm.php
View source
<?php
namespace Drupal\broken_link\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class BrokenLinkDeleteForm extends EntityConfirmFormBase {
public function getQuestion() {
return $this
->t('Are you sure you want to delete the broken link?', []);
}
public function getCancelUrl() {
return new Url('entity.broken_link.collection');
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form['#title'] = $this
->getQuestion();
$form['#attributes']['class'][] = 'confirmation';
$form['description'] = array(
'#markup' => $this
->getDescription(),
);
$form[$this
->getFormName()] = array(
'#type' => 'hidden',
'#value' => 1,
);
if (!isset($form['#theme'])) {
$form['#theme'] = 'confirm_form';
}
$actions = $this
->actionsElement($form, $form_state);
if (!empty($actions)) {
$form['actions'] = $actions;
}
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity
->delete();
drupal_set_message($this
->t('content @type deleted.', [
'@type' => $this->entity
->bundle(),
]));
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
}