Creates a form to delete an image style.
Expanded class hierarchy of ImageStyleDeleteForm
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';
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfirmFormBase:: |
protected | function | Returns a caption for the link which cancels the action. | 2 |
ConfirmFormBase:: |
protected | function | Returns the internal name used to refer to the confirmation item. | |
ConfirmFormBase:: |
public | function |
Implements \Drupal\Core\Form\FormInterface::validateForm(). Overrides FormInterface:: |
1 |
ImageStyleDeleteForm:: |
protected | property | The image style to be deleted. | |
ImageStyleDeleteForm:: |
public | function |
Implements \Drupal\Core\Form\FormInterface::buildForm(). Overrides ConfirmFormBase:: |
|
ImageStyleDeleteForm:: |
protected | function |
Returns the page to go to if the user cancels the action. Overrides ConfirmFormBase:: |
|
ImageStyleDeleteForm:: |
protected | function |
Returns a caption for the button that confirms the action. Overrides ConfirmFormBase:: |
|
ImageStyleDeleteForm:: |
protected | function |
Returns additional text to display as a description. Overrides ConfirmFormBase:: |
|
ImageStyleDeleteForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
ImageStyleDeleteForm:: |
protected | function |
Returns the question to ask the user. Overrides ConfirmFormBase:: |
|
ImageStyleDeleteForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |