Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ValeriiVasyliev/7772251cad2126496a86ed2d808089a4 to your computer and use it in GitHub Desktop.
Save ValeriiVasyliev/7772251cad2126496a86ed2d808089a4 to your computer and use it in GitHub Desktop.
Drupal 8. Upload file and set statuds permanent
<?php
$fid = $form_state->getValue('file');
if (isset($fid[0]) && $fid[0] > 0) {
$file = \Drupal\file\Entity\File::load($fid[0]);
$file->setPermanent();
$file->save();
\Drupal::service('file.usage')->add($file, 'name', 'name', $id);
$options['file'] = $fid[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment