You are here

WebformCompositeDeleteForm.php in Webform Composite Tools 8

File

src/Form/WebformCompositeDeleteForm.php
View source
<?php

namespace Drupal\webform_composite\Form;

use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;

/**
 * Defines WebforCompositeDeleteForm.
 */
class WebformCompositeDeleteForm extends EntityConfirmFormBase {

  /**
   * {@inheritdoc}
   */
  public function getQuestion() {
    return $this
      ->t('Are you sure you want to delete the Composite %label?', [
      '%label' => $this->entity
        ->label(),
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function getConfirmText() {
    return $this
      ->t('Delete');
  }

  /**
   * {@inheritdoc}
   */
  public function getCancelUrl() {
    return new Url('entity.webform_composite.list');
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {

    // Delete the entity.
    $this->entity
      ->delete();

    // Set a message that the entity was deleted.
    $this
      ->messenger()
      ->addMessage($this
      ->t('Composite %label was deleted.', [
      '%label' => $this->entity
        ->label(),
    ]));

    // Redirect the user to the list controller when complete.
    $form_state
      ->setRedirectUrl($this
      ->getCancelUrl());
  }

}

Classes

Namesort descending Description
WebformCompositeDeleteForm Defines WebforCompositeDeleteForm.