Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\migrate_tools\Form;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Entity\EntityConfirmFormBase;
|
Chris@0
|
6 use Drupal\Core\Url;
|
Chris@0
|
7 use Drupal\Core\Form\FormStateInterface;
|
Chris@0
|
8
|
Chris@0
|
9 /**
|
Chris@0
|
10 * Class MigrationDeleteForm.
|
Chris@0
|
11 *
|
Chris@0
|
12 * @package Drupal\migrate_tools\Form
|
Chris@0
|
13 *
|
Chris@0
|
14 * @ingroup migrate_tools
|
Chris@0
|
15 */
|
Chris@0
|
16 class MigrationDeleteForm extends EntityConfirmFormBase {
|
Chris@0
|
17
|
Chris@0
|
18 /**
|
Chris@0
|
19 * Gathers a confirmation question.
|
Chris@0
|
20 *
|
Chris@0
|
21 * @return string
|
Chris@0
|
22 * Translated string.
|
Chris@0
|
23 */
|
Chris@0
|
24 public function getQuestion() {
|
Chris@0
|
25 return $this->t('Are you sure you want to delete migration %label?', array(
|
Chris@0
|
26 '%label' => $this->entity->label(),
|
Chris@0
|
27 ));
|
Chris@0
|
28 }
|
Chris@0
|
29
|
Chris@0
|
30 /**
|
Chris@0
|
31 * Gather the confirmation text.
|
Chris@0
|
32 *
|
Chris@0
|
33 * @return string
|
Chris@0
|
34 * Translated string.
|
Chris@0
|
35 */
|
Chris@0
|
36 public function getConfirmText() {
|
Chris@0
|
37 return $this->t('Delete Migration');
|
Chris@0
|
38 }
|
Chris@0
|
39
|
Chris@0
|
40 /**
|
Chris@0
|
41 * Gets the cancel URL.
|
Chris@0
|
42 *
|
Chris@0
|
43 * @return \Drupal\Core\Url
|
Chris@0
|
44 * The URL to go to if the user cancels the deletion.
|
Chris@0
|
45 */
|
Chris@0
|
46 public function getCancelUrl() {
|
Chris@0
|
47 return new Url('entity.migration.list', array('migration_group' => $this->entity->get('migration_group')));
|
Chris@0
|
48 }
|
Chris@0
|
49
|
Chris@0
|
50 /**
|
Chris@0
|
51 * The submit handler for the confirm form.
|
Chris@0
|
52 *
|
Chris@0
|
53 * @param array $form
|
Chris@0
|
54 * An associative array containing the structure of the form.
|
Chris@0
|
55 * @param \Drupal\Core\Form\FormStateInterface $form_state
|
Chris@0
|
56 * An associative array containing the current state of the form.
|
Chris@0
|
57 */
|
Chris@0
|
58 public function submitForm(array &$form, FormStateInterface $form_state) {
|
Chris@0
|
59 // Delete the entity.
|
Chris@0
|
60 $this->entity->delete();
|
Chris@0
|
61
|
Chris@0
|
62 // Set a message that the entity was deleted.
|
Chris@0
|
63 drupal_set_message(t('Migration %label was deleted.', array(
|
Chris@0
|
64 '%label' => $this->entity->label(),
|
Chris@0
|
65 )));
|
Chris@0
|
66
|
Chris@0
|
67 // Redirect the user to the list controller when complete.
|
Chris@0
|
68 $form_state->setRedirectUrl($this->getCancelUrl(),
|
Chris@0
|
69 array('migration_group' => $this->entity->get('migration_group')));
|
Chris@0
|
70 }
|
Chris@0
|
71
|
Chris@0
|
72 }
|