Commit 1ebed3a0 authored by alexpott's avatar alexpott

Issue #1946416 by kim.pepper: Convert all of confirm_form() in image.admin.inc...

Issue #1946416 by kim.pepper: Convert all of confirm_form() in image.admin.inc to the new form interface.
parent 17f4d142
......@@ -259,46 +259,6 @@ function image_style_add_form_submit($form, &$form_state) {
$form_state['redirect'] = 'admin/config/media/image-styles/manage/' . $style->id();
}
/**
* Form builder; Form for deleting an image style.
*
* @param $style
* An image style array.
*
* @ingroup forms
* @see image_style_delete_form_submit()
*/
function image_style_delete_form($form, &$form_state, $style) {
$form_state['image_style'] = $style;
$replacement_styles = array_diff_key(image_style_options(), array($style->id() => ''));
$form['replacement'] = array(
'#title' => t('Replacement style'),
'#type' => 'select',
'#options' => $replacement_styles,
'#empty_option' => t('No replacement, just delete'),
);
return confirm_form(
$form,
t('Optionally select a style before deleting %style', array('%style' => $style->label())),
'admin/config/media/image-styles',
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.'),
t('Delete'), t('Cancel')
);
}
/**
* Submit handler to delete an image style.
*/
function image_style_delete_form_submit($form, &$form_state) {
$style = $form_state['image_style'];
$style->set('replacementID', $form_state['values']['replacement']);
$style->delete();
drupal_set_message(t('Style %name was deleted.', array('%name' => $style->label())));
$form_state['redirect'] = 'admin/config/media/image-styles';
}
/**
* Form builder; Form for adding and editing image effects.
*
......@@ -385,36 +345,6 @@ function image_effect_form_submit($form, &$form_state) {
$form_state['redirect'] = 'admin/config/media/image-styles/manage/' . $style->id();
}
/**
* Form builder; Form for deleting an image effect.
*
* @param $style
* Name of the image style from which the image effect will be removed.
* @param $effect
* Name of the image effect to remove.
* @ingroup forms
* @see image_effect_delete_form_submit()
*/
function image_effect_delete_form($form, &$form_state, $style, $effect) {
$form_state['image_style'] = $style;
$form_state['image_effect'] = $effect;
$question = t('Are you sure you want to delete the @effect effect from the %style style?', array('%style' => $style->label(), '@effect' => $effect['label']));
return confirm_form($form, $question, 'admin/config/media/image-styles/manage/' . $style->id(), '', t('Delete'));
}
/**
* Submit handler to delete an image effect.
*/
function image_effect_delete_form_submit($form, &$form_state) {
$style = $form_state['image_style'];
$effect = $form_state['image_effect'];
image_effect_delete($style, $effect);
drupal_set_message(t('The image effect %name has been deleted.', array('%name' => $effect['label'])));
$form_state['redirect'] = 'admin/config/media/image-styles/manage/' . $style->id();
}
/**
* Element validate handler to ensure a hexadecimal color value.
*/
......
......@@ -156,13 +156,9 @@ function image_menu() {
$items['admin/config/media/image-styles/manage/%image_style/delete'] = array(
'title' => 'Delete',
'description' => 'Delete an image style.',
'load arguments' => array(NULL, (string) IMAGE_STORAGE_NORMAL),
'page callback' => 'drupal_get_form',
'page arguments' => array('image_style_delete_form', 5),
'access arguments' => array('administer image styles'),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
'file' => 'image.admin.inc',
'route_name' => 'image_style_delete',
);
$items['admin/config/media/image-styles/manage/%image_style/effects/%image_effect'] = array(
'title' => 'Edit image effect',
......@@ -176,11 +172,7 @@ function image_menu() {
$items['admin/config/media/image-styles/manage/%image_style/effects/%image_effect/delete'] = array(
'title' => 'Delete image effect',
'description' => 'Delete an existing effect from a style.',
'load arguments' => array(5, (string) IMAGE_STORAGE_EDITABLE),
'page callback' => 'drupal_get_form',
'page arguments' => array('image_effect_delete_form', 5, 7),
'access arguments' => array('administer image styles'),
'file' => 'image.admin.inc',
'route_name' => 'image_effect_delete',
);
$items['admin/config/media/image-styles/manage/%image_style/add/%image_effect_definition'] = array(
'title' => 'Add image effect',
......
image_style_delete:
pattern: 'admin/config/media/image-styles/manage/{image_style}/delete'
defaults:
_form: '\Drupal\image\Form\ImageStyleDeleteForm'
requirements:
_permission: 'administer image styles'
image_effect_delete:
pattern: 'admin/config/media/image-styles/manage/{image_style}/effects/{image_effect}/delete'
defaults:
_form: '\Drupal\image\Form\ImageEffectDeleteForm'
requirements:
_permission: 'administer image styles'
<?php
/**
* @file
* Contains \Drupal\image\Form\ImageEffectDeleteForm.
*/
namespace Drupal\image\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\image\Plugin\Core\Entity\ImageStyle;
/**
* Form for deleting an image effect.
*/
class ImageEffectDeleteForm extends ConfirmFormBase {
/**
* The image style containing the image effect to be deleted.
*
* @var \Drupal\image\Plugin\Core\Entity\ImageStyle
*/
protected $imageStyle;
/**
* The image effect to be deleted.
*
* @var array;
*/
protected $imageEffect;
/**
* {@inheritdoc}
*/
protected function getQuestion() {
return t('Are you sure you want to delete the @effect effect from the %style style?', array('%style' => $this->imageStyle->label(), '@effect' => $this->imageEffect['label']));
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
return 'admin/config/media/image-styles/manage/' . $this->imageStyle->id();
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'image_effect_delete_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, $image_style = NULL, $image_effect = NULL) {
$this->imageStyle = $image_style;
$this->imageEffect = image_effect_load($image_effect, $this->imageStyle->id());
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
image_effect_delete($this->imageStyle, $this->imageEffect);
drupal_set_message(t('The image effect %name has been deleted.', array('%name' => $this->imageEffect['label'])));
$form_state['redirect'] = 'admin/config/media/image-styles/manage/' . $this->imageStyle->id();
}
}
<?php
/**
* @file
* Contains \Drupal\image\Form\ImageStyleDeleteForm.
*/
namespace Drupal\image\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\image\Plugin\Core\Entity\ImageStyle;
/**
* Creates a form to delete an image style.
*/
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';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment