class ImageStyleDeleteForm

Creates a form to delete an image style.

Hierarchy

Expanded class hierarchy of ImageStyleDeleteForm

1 string reference to 'ImageStyleDeleteForm'
image.routing.yml in drupal/core/modules/image/image.routing.yml
drupal/core/modules/image/image.routing.yml

File

drupal/core/modules/image/lib/Drupal/image/Form/ImageStyleDeleteForm.php, line 16
Contains \Drupal\image\Form\ImageStyleDeleteForm.

Namespace

Drupal\image\Form
View source
class ImageStyleDeleteForm extends ConfirmFormBase {

  /**
   * The image style to be deleted.
   *
   * @var \Drupal\image\Plugin\Core\Entity\ImageStyle $imageStyle
   */
  protected $imageStyle;

  /**
   * {@inheritdoc}
   */
  protected function getQuestion() {
    return t('Optionally select a style before deleting %style', array(
      '%style' => $this->imageStyle
        ->label(),
    ));
  }

  /**
   * {@inheritdoc}
   */
  protected function getConfirmText() {
    return t('Delete');
  }

  /**
   * {@inheritdoc}
   */
  protected function getCancelPath() {
    return 'admin/config/media/image-styles';
  }

  /**
   * {@inheritdoc}
   */
  public function getFormID() {
    return 'image_style_delete_form';
  }

  /**
   * {@inheritdoc}
   */
  protected function getDescription() {
    return t('If this style is in use on the site, you may select another style to replace it. All images that have been generated for this style will be permanently deleted.');
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, array &$form_state, ImageStyle $image_style = NULL) {
    $this->imageStyle = $image_style;
    $replacement_styles = array_diff_key(image_style_options(), array(
      $this->imageStyle
        ->id() => '',
    ));
    $form['replacement'] = array(
      '#title' => t('Replacement style'),
      '#type' => 'select',
      '#options' => $replacement_styles,
      '#empty_option' => t('No replacement, just delete'),
    );
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, array &$form_state) {
    $this->imageStyle
      ->set('replacementID', $form_state['values']['replacement']);
    $this->imageStyle
      ->delete();
    drupal_set_message(t('Style %name was deleted.', array(
      '%name' => $this->imageStyle
        ->label(),
    )));
    $form_state['redirect'] = 'admin/config/media/image-styles';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfirmFormBase::getCancelText protected function Returns a caption for the link which cancels the action. 2
ConfirmFormBase::getFormName protected function Returns the internal name used to refer to the confirmation item.
ConfirmFormBase::validateForm public function Implements \Drupal\Core\Form\FormInterface::validateForm(). Overrides FormInterface::validateForm 1
ImageStyleDeleteForm::$imageStyle protected property The image style to be deleted.
ImageStyleDeleteForm::buildForm public function Implements \Drupal\Core\Form\FormInterface::buildForm(). Overrides ConfirmFormBase::buildForm
ImageStyleDeleteForm::getCancelPath protected function Returns the page to go to if the user cancels the action. Overrides ConfirmFormBase::getCancelPath
ImageStyleDeleteForm::getConfirmText protected function Returns a caption for the button that confirms the action. Overrides ConfirmFormBase::getConfirmText
ImageStyleDeleteForm::getDescription protected function Returns additional text to display as a description. Overrides ConfirmFormBase::getDescription
ImageStyleDeleteForm::getFormID public function Returns a unique string identifying the form. Overrides FormInterface::getFormID
ImageStyleDeleteForm::getQuestion protected function Returns the question to ask the user. Overrides ConfirmFormBase::getQuestion
ImageStyleDeleteForm::submitForm public function Form submission handler. Overrides FormInterface::submitForm