You are here

RuleDeleteForm.php in RNG - Events and Registrations 3.x

Same filename and directory in other branches
  1. 8.2 src/Form/RuleDeleteForm.php
  2. 8 src/Form/RuleDeleteForm.php

Namespace

Drupal\rng\Form

File

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

namespace Drupal\rng\Form;

use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Form for deleting a rng rule.
 */
class RuleDeleteForm extends ContentEntityConfirmFormBase {

  /**
   * {@inheritdoc}
   */
  public function getQuestion() {
    return t('Are you sure you want to delete this rule?');
  }

  /**
   * {@inheritdoc}
   */
  public function getCancelUrl() {
    return $this->entity
      ->getEvent()
      ->urlInfo();
  }

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

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $rule = $this->entity;
    $rule
      ->delete();
    $event = $rule
      ->getEvent();
    $this
      ->messenger()
      ->addMessage(t('Rule deleted.'));
    if ($urlInfo = $event
      ->urlInfo()) {
      $form_state
        ->setRedirectUrl($urlInfo);
    }
  }

}

Classes

Namesort descending Description
RuleDeleteForm Form for deleting a rng rule.