3 namespace Drupal\{{ machine_name }}\Form;
5 use Drupal\Core\Database\Connection;
6 use Drupal\Core\Form\ConfirmFormBase;
7 use Drupal\Core\Form\FormStateInterface;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
12 * Provides a confirmation form before clearing out the examples.
14 class {{ class }} extends ConfirmFormBase {
17 * The database connection.
19 * @var \Drupal\Core\Database\Connection
21 protected $connection;
24 * Constructs new {{ class }} object.
26 * @param \Drupal\Core\Database\Connection $connection
27 * The database connection.
29 public function __construct(Connection $connection) {
30 $this->connection = $connection;
36 public static function create(ContainerInterface $container) {
38 $container->get('database')
45 public function getFormId() {
46 return '{{ form_id }}';
52 public function getQuestion() {
53 return $this->t('Are you sure you want to delete all examples?');
59 public function getCancelUrl() {
60 return new Url('system.admin');
66 public function submitForm(array &$form, FormStateInterface $form_state) {
67 $this->connection->delete('examples')->execute();
68 drupal_set_message($this->t('The examples have been deleted.'));
69 $form_state->setRedirectUrl($this->getCancelUrl());