ImageEffectDeleteForm.php 1.8 KB
Newer Older
1 2 3 4 5
<?php

namespace Drupal\image\Form;

use Drupal\Core\Form\ConfirmFormBase;
6
use Drupal\Core\Form\FormStateInterface;
7
use Drupal\image\ImageStyleInterface;
8 9 10

/**
 * Form for deleting an image effect.
11 12
 *
 * @internal
13 14 15 16 17 18
 */
class ImageEffectDeleteForm extends ConfirmFormBase {

  /**
   * The image style containing the image effect to be deleted.
   *
19
   * @var \Drupal\image\ImageStyleInterface
20 21 22 23 24 25
   */
  protected $imageStyle;

  /**
   * The image effect to be deleted.
   *
26
   * @var \Drupal\image\ImageEffectInterface
27 28 29 30 31 32
   */
  protected $imageEffect;

  /**
   * {@inheritdoc}
   */
33
  public function getQuestion() {
34
    return $this->t('Are you sure you want to delete the @effect effect from the %style style?', ['%style' => $this->imageStyle->label(), '@effect' => $this->imageEffect->label()]);
35 36 37 38 39
  }

  /**
   * {@inheritdoc}
   */
40
  public function getConfirmText() {
41
    return $this->t('Delete');
42 43 44 45 46
  }

  /**
   * {@inheritdoc}
   */
47
  public function getCancelUrl() {
48
    return $this->imageStyle->urlInfo('edit-form');
49 50 51 52 53
  }

  /**
   * {@inheritdoc}
   */
54
  public function getFormId() {
55 56 57 58 59 60
    return 'image_effect_delete_form';
  }

  /**
   * {@inheritdoc}
   */
61
  public function buildForm(array $form, FormStateInterface $form_state, ImageStyleInterface $image_style = NULL, $image_effect = NULL) {
62
    $this->imageStyle = $image_style;
63
    $this->imageEffect = $this->imageStyle->getEffect($image_effect);
64

65
    return parent::buildForm($form, $form_state);
66 67 68 69 70
  }

  /**
   * {@inheritdoc}
   */
71
  public function submitForm(array &$form, FormStateInterface $form_state) {
72
    $this->imageStyle->deleteImageEffect($this->imageEffect);
73
    drupal_set_message($this->t('The image effect %name has been deleted.', ['%name' => $this->imageEffect->label()]));
74
    $form_state->setRedirectUrl($this->imageStyle->urlInfo('edit-form'));
75 76 77
  }

}