You are here

BrokenLinkRedirectDeleteForm.php in Broken Link 8.2

File

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

namespace Drupal\broken_link\Form;

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

/**
 * Builds the form to delete Broken link redirect entity entities.
 */
class BrokenLinkRedirectDeleteForm extends EntityConfirmFormBase {

  /**
   * {@inheritdoc}
   */
  public function getQuestion() {
    return $this
      ->t('Are you sure you want to delete the broken link redirect?', []);
  }

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

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

  /**
   * {@inheritdoc}
   */
  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,
    );

    // By default, render the form using theme_confirm_form().
    if (!isset($form['#theme'])) {
      $form['#theme'] = 'confirm_form';
    }
    $actions = $this
      ->actionsElement($form, $form_state);
    if (!empty($actions)) {
      $form['actions'] = $actions;
    }
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  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());
  }

}

Classes

Namesort descending Description
BrokenLinkRedirectDeleteForm Builds the form to delete Broken link redirect entity entities.