RecordshortenClearAll.php in Shorten URLs 8.2
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;
class RecordshortenClearAll extends FormBase {
public function getFormId() {
return 'record_shorten_clear_all';
}
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;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
\Drupal::database()
->query("TRUNCATE TABLE {record_shorten}");
$this
->messenger()
->addStatus('Shorten Url records cleared.');
}
}