Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / form / confirm.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/form/confirm.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/form/confirm.twig
new file mode 100644 (file)
index 0000000..4e28d64
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+
+namespace Drupal\{{ machine_name }}\Form;
+
+use Drupal\Core\Database\Connection;
+use Drupal\Core\Form\ConfirmFormBase;
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Url;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Provides a confirmation form before clearing out the examples.
+ */
+class {{ class }} extends ConfirmFormBase {
+
+  /**
+   * The database connection.
+   *
+   * @var \Drupal\Core\Database\Connection
+   */
+  protected $connection;
+
+  /**
+   * Constructs new {{ class }} object.
+   *
+   * @param \Drupal\Core\Database\Connection $connection
+   *   The database connection.
+   */
+  public function __construct(Connection $connection) {
+    $this->connection = $connection;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container) {
+    return new static(
+      $container->get('database')
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getFormId() {
+    return '{{ form_id }}';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getQuestion() {
+    return $this->t('Are you sure you want to delete all examples?');
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getCancelUrl() {
+    return new Url('system.admin');
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function submitForm(array &$form, FormStateInterface $form_state) {
+    $this->connection->delete('examples')->execute();
+    drupal_set_message($this->t('The examples have been deleted.'));
+    $form_state->setRedirectUrl($this->getCancelUrl());
+  }
+
+}