You are here

public function ImageAPIOptimizePipelineEditForm::processorSave in Image Optimize (or ImageAPI Optimize) 8.3

Same name and namespace in other branches
  1. 8.2 src/Form/ImageAPIOptimizePipelineEditForm.php \Drupal\imageapi_optimize\Form\ImageAPIOptimizePipelineEditForm::processorSave()
  2. 4.x src/Form/ImageAPIOptimizePipelineEditForm.php \Drupal\imageapi_optimize\Form\ImageAPIOptimizePipelineEditForm::processorSave()

Submit handler for image optimize processor.

File

src/Form/ImageAPIOptimizePipelineEditForm.php, line 194

Class

ImageAPIOptimizePipelineEditForm
Controller for image optimize pipeline edit form.

Namespace

Drupal\imageapi_optimize\Form

Code

public function processorSave($form, FormStateInterface $form_state) {
  $this
    ->save($form, $form_state);

  // Check if this field has any configuration options.
  $processor = $this->imageAPIOptimizeProcessorManager
    ->getDefinition($form_state
    ->getValue('new'));

  // Load the configuration form for this option.
  if (is_subclass_of($processor['class'], '\\Drupal\\imageapi_optimize\\ConfigurableImageAPIOptimizeProcessorInterface')) {
    $form_state
      ->setRedirect('imageapi_optimize.processor_add_form', [
      'imageapi_optimize_pipeline' => $this->entity
        ->id(),
      'imageapi_optimize_processor' => $form_state
        ->getValue('new'),
    ], [
      'query' => [
        'weight' => $form_state
          ->getValue('weight'),
      ],
    ]);
  }
  else {
    $processor = [
      'id' => $processor['id'],
      'data' => [],
      'weight' => $form_state
        ->getValue('weight'),
    ];
    $processor_id = $this->entity
      ->addProcessor($processor);
    $this->entity
      ->save();
    if (!empty($processor_id)) {
      $this
        ->messenger()
        ->addMessage($this
        ->t('The Image Optimize processor was successfully applied.'));
    }
  }
}