I had the same problem with the file
form element. Solved this by using managed_file
and providing the upload location and validators in the form element:
$form['test_CERTIFICATE'] = [
'#type' => 'managed_file',
'#title' => $this->t('Certificate'),
'#upload_location' => 'private://certfiles',
'#upload_validators' => [
'file_validate_extensions' => ['pem'],
],
];
Then in submit:
use Drupal\file\Entity\File;
$fid$form_file = $form_state->getValue(['test_CERTIFICATE''test_CERTIFICATE', 0]0);
if (isset($form_file[0]) && !empty($fid$form_file[0])) {
$file = File::load($fid$form_file[0]);
$file->setPermanent();
$file->save();
}