Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / form / confirm.twig
1 <?php
2
3 namespace Drupal\{{ machine_name }}\Form;
4
5 use Drupal\Core\Database\Connection;
6 use Drupal\Core\Form\ConfirmFormBase;
7 use Drupal\Core\Form\FormStateInterface;
8 use Drupal\Core\Url;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
10
11 /**
12  * Provides a confirmation form before clearing out the examples.
13  */
14 class {{ class }} extends ConfirmFormBase {
15
16   /**
17    * The database connection.
18    *
19    * @var \Drupal\Core\Database\Connection
20    */
21   protected $connection;
22
23   /**
24    * Constructs new {{ class }} object.
25    *
26    * @param \Drupal\Core\Database\Connection $connection
27    *   The database connection.
28    */
29   public function __construct(Connection $connection) {
30     $this->connection = $connection;
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   public static function create(ContainerInterface $container) {
37     return new static(
38       $container->get('database')
39     );
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public function getFormId() {
46     return '{{ form_id }}';
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function getQuestion() {
53     return $this->t('Are you sure you want to delete all examples?');
54   }
55
56   /**
57    * {@inheritdoc}
58    */
59   public function getCancelUrl() {
60     return new Url('system.admin');
61   }
62
63   /**
64    * {@inheritdoc}
65    */
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());
70   }
71
72 }