diff modules/contrib/migrate_tools/src/Form/MigrationDeleteForm.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/contrib/migrate_tools/src/Form/MigrationDeleteForm.php	Wed Nov 29 16:09:58 2017 +0000
@@ -0,0 +1,72 @@
+<?php
+
+namespace Drupal\migrate_tools\Form;
+
+use Drupal\Core\Entity\EntityConfirmFormBase;
+use Drupal\Core\Url;
+use Drupal\Core\Form\FormStateInterface;
+
+/**
+ * Class MigrationDeleteForm.
+ *
+ * @package Drupal\migrate_tools\Form
+ *
+ * @ingroup migrate_tools
+ */
+class MigrationDeleteForm extends EntityConfirmFormBase {
+
+  /**
+   * Gathers a confirmation question.
+   *
+   * @return string
+   *   Translated string.
+   */
+  public function getQuestion() {
+    return $this->t('Are you sure you want to delete migration %label?', array(
+        '%label' => $this->entity->label(),
+    ));
+  }
+
+  /**
+   * Gather the confirmation text.
+   *
+   * @return string
+   *   Translated string.
+   */
+  public function getConfirmText() {
+    return $this->t('Delete Migration');
+  }
+
+  /**
+   * Gets the cancel URL.
+   *
+   * @return \Drupal\Core\Url
+   *   The URL to go to if the user cancels the deletion.
+   */
+  public function getCancelUrl() {
+    return new Url('entity.migration.list', array('migration_group' => $this->entity->get('migration_group')));
+  }
+
+  /**
+   * The submit handler for the confirm form.
+   *
+   * @param array $form
+   *   An associative array containing the structure of the form.
+   * @param \Drupal\Core\Form\FormStateInterface $form_state
+   *   An associative array containing the current state of the form.
+   */
+  public function submitForm(array &$form, FormStateInterface $form_state) {
+    // Delete the entity.
+    $this->entity->delete();
+
+    // Set a message that the entity was deleted.
+    drupal_set_message(t('Migration %label was deleted.', array(
+      '%label' => $this->entity->label(),
+    )));
+
+    // Redirect the user to the list controller when complete.
+    $form_state->setRedirectUrl($this->getCancelUrl(),
+          array('migration_group' => $this->entity->get('migration_group')));
+  }
+
+}