Created
May 26, 2017 16:05
-
-
Save ValeriiVasyliev/7772251cad2126496a86ed2d808089a4 to your computer and use it in GitHub Desktop.
Drupal 8. Upload file and set statuds permanent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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