You are here

public function UploadForm::submitForm in Filebrowser 8.2

Same name and namespace in other branches
  1. 3.x src/Form/UploadForm.php \Drupal\filebrowser\Form\UploadForm::submitForm()

@inheritdoc

Overrides FormInterface::submitForm

File

src/Form/UploadForm.php, line 99

Class

UploadForm

Namespace

Drupal\filebrowser\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // While we are using the managed_file widget (for convenience), we don't
  // want to save the file in the file_managed table, so we will delete it
  // here.
  // A bit hackish, but it works.
  $file_ids = $form_state
    ->getValue('u_file');
  if (count($file_ids)) {
    $success = \Drupal::service('filebrowser.storage')
      ->genericDeleteMultiple('file_managed', 'fid', join(',', $file_ids));
    if ($success) {
      \Drupal::messenger()
        ->addMessage($this
        ->t("Your filebrowser upload is completed successfully!"));
    }
    else {
      \Drupal::messenger()
        ->addError($this
        ->t('Your upload completed successfully, but file_managed clean-up failed'));
    }
  }

  // invalidate the cache for this node
  Cache::invalidateTags([
    'filebrowser:node:' . $this->nid,
  ]);
  $route = $this->common
    ->redirectRoute($this->queryFid, $this->node
    ->id());
  $form_state
    ->setRedirect($route['name'], $route['node'], $route['query']);
}