You are here

public function DeleteForm::submitForm in bootstrap simple carousel 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/DeleteForm.php, line 114

Class

DeleteForm
Class DeleteForm.

Namespace

Drupal\bootstrap_simple_carousel\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $message = $this
    ->t('Item has been removed!');
  if (!is_null($this->entity)) {
    $file = $this->entityTypeManager
      ->getStorage('file')
      ->load($form_state
      ->getValue('image_id'));
    $file
      ->setTemporary();
    $file
      ->save();
    try {
      $this->entity
        ->delete();
    } catch (\Exception $e) {
      $message = $this
        ->t('Item was not removed!');
    }
  }
  $this
    ->messenger()
    ->addMessage($message);
  $form_state
    ->setRedirect('bootstrap_simple_carousel.table');
}