You are here

RecordshortenClearAll.php in Shorten URLs 8.2

Same filename and directory in other branches
  1. 8 modules/record_shorten/src/Form/RecordshortenClearAll.php

File

modules/record_shorten/src/Form/RecordshortenClearAll.php
View source
<?php

namespace Drupal\record_shorten\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Report form.
 */
class RecordshortenClearAll extends FormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'record_shorten_clear_all';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['warning'] = [
      '#markup' => '<p><strong>' . t('Warning: there is no confirmation page. Cleared records are permanently deleted.') . '</strong></p>',
    ];
    $form['note'] = [
      '#markup' => '<p>' . t('Note: clearing records does not clear the Shorten URLs cache.') . ' ' . t('Also, URLs already in the cache are not recorded again.') . '</p>',
    ];
    $form['clear'] = [
      '#type' => 'submit',
      '#value' => t('Clear all records'),
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    \Drupal::database()
      ->query("TRUNCATE TABLE {record_shorten}");
    $this
      ->messenger()
      ->addStatus('Shorten Url records cleared.');
  }

}

Classes

Namesort descending Description
RecordshortenClearAll Report form.