ImageAPIOptimizeProcessorDeleteForm.php in Image Optimize (or ImageAPI Optimize) 8.2
File
src/Form/ImageAPIOptimizeProcessorDeleteForm.php
View source
<?php
namespace Drupal\imageapi_optimize\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\imageapi_optimize\ImageAPIOptimizePipelineInterface;
class ImageAPIOptimizeProcessorDeleteForm extends ConfirmFormBase {
protected $imageAPIOptimizePipeline;
protected $imageAPIOptimizeProcessor;
public function getQuestion() {
return $this
->t('Are you sure you want to delete the @processor processor from the %pipeline pipeline?', [
'%pipeline' => $this->imageAPIOptimizePipeline
->label(),
'@processor' => $this->imageAPIOptimizeProcessor
->label(),
]);
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function getCancelUrl() {
return $this->imageAPIOptimizePipeline
->toUrl('edit-form');
}
public function getFormId() {
return 'imageapi_optimize_processor_delete_form';
}
public function buildForm(array $form, FormStateInterface $form_state, ImageAPIOptimizePipelineInterface $imageapi_optimize_pipeline = NULL, $imageapi_optimize_processor = NULL) {
$this->imageAPIOptimizePipeline = $imageapi_optimize_pipeline;
$this->imageAPIOptimizeProcessor = $this->imageAPIOptimizePipeline
->getProcessor($imageapi_optimize_processor);
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->imageAPIOptimizePipeline
->deleteProcessor($this->imageAPIOptimizeProcessor);
$this
->messenger()
->addMessage($this
->t('The Image Optimize processor %name has been deleted.', [
'%name' => $this->imageAPIOptimizeProcessor
->label(),
]));
$form_state
->setRedirectUrl($this->imageAPIOptimizePipeline
->toUrl('edit-form'));
}
}