You are here

public function FileManagementDeleteFileConfirmForm::submitForm in File Management 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/FileManagementDeleteFileConfirmForm.php, line 93

Class

FileManagementDeleteFileConfirmForm
Defines a confirmation form for deleting mymodule data.

Namespace

Drupal\file_management\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  if (file_exists($this->file
    ->getFileUri())) {
    $this->file
      ->delete();
    \Drupal::messenger()
      ->addMessage(t('File "%label" has been deleted.', [
      '%label' => $this->file
        ->label(),
    ]), 'status');
  }
  else {
    \Drupal::messenger()
      ->addMessage(t('File "%label" could not be deleted.', [
      '%label' => $this->file
        ->label(),
    ]), 'error');
  }
}