Completed
Pull Request — 8.x-1.x (#137)
by
unknown
16:44 queued 12s
created

EntityBrowserDeleteForm::getCancelUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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