Created
May 14, 2019 14:47
-
-
Save fazni/79632cf51a51296bf5d3d4fa4964c860 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$form['file'] = [ | |
'#type' => 'managed_file', | |
'#title' => t('File'), | |
'#upload_location' => 'public://file', | |
'#upload_validators' => [ | |
'file_validate_extensions' => ['csv'], | |
], | |
'#default_value' => array(2) | |
]; | |
Handle the saving the file as a permanent file into the file_managed table. So add this to your submit handler. | |
use Drupal\file\Entity\File; | |
$fid = $form_state->getValue(['file', 0]); | |
if (!empty($fid)) { | |
$file = File::load($fid); | |
$file->setPermanent(); | |
$file->save(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment