CustomContextualLinkDeleteForm.php in Custom Contextual Links 8.2
File
src/Form/CustomContextualLinkDeleteForm.php
View source
<?php
namespace Drupal\ccl\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class CustomContextualLinkDeleteForm extends EntityConfirmFormBase {
public function getQuestion() {
return $this
->t('Are you sure you want to delete %name?', [
'%name' => $this->entity
->label(),
]);
}
public function getCancelUrl() {
return new Url('entity.custom_contextual_link.collection');
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$form['#attached']['library'][] = 'ccl/ccl';
$form['#attributes']['class'][] = 'ccl-form';
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
try {
$this->entity
->delete();
$this
->messenger()
->addMessage($this
->t('content @type: deleted @label.', [
'@type' => $this->entity
->bundle(),
'@label' => $this->entity
->label(),
]));
} catch (EntityStorageException $exception) {
$this
->logger('ccl')
->error($exception
->getMessage());
$this
->messenger()
->addError($this
->t('Could not delete entity. See the error log for more details.'));
}
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
}