MiconDeleteForm.php in Micon 2.x        
                          
                  
                        
  
  
  
  
File
  src/Form/MiconDeleteForm.php
  
    View source  
  <?php
namespace Drupal\micon\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class MiconDeleteForm 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.micon.collection');
  }
  
  public function getConfirmText() {
    return $this
      ->t('Delete');
  }
  
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->entity
      ->delete();
    $this
      ->messenger()
      ->addStatus($this
      ->t('Micon package @label has been removed.', [
      '@label' => $this->entity
        ->label(),
    ]));
    drupal_flush_all_caches();
    $form_state
      ->setRedirectUrl($this
      ->getCancelUrl());
  }
}