I have a content entity type, and I would like to have an 'Upload file' field. I have declared the field in my Entity class
$fields['file'] = BaseFieldDefinition::create('file')
->setLabel(t('Upload a file'))
->setDescription(t('Choose file from your computer'));
And in EntityForm I am trying to set some settings, because I need to make this dependable later with the '#states'
$form['file'] = [
'#title' => $this->t('File'),
'#description' => $this->t('Upload a file from your computer'),
'#type' => 'file',
'#default_value' => $entity->file->value,
];
But at the moment the field is displayed, but I have problems on saving the form. The file is attached, but not getting uploaded and the error says:
Fatal error: Call to a member function getValue() on a non-object in C:\A plus\drupalsite\core\modules\file\src\Plugin\Validation\Constraint\FileValidationConstraintValidator.php on line 18
->setDisplayConfigurable('form', TRUE)
and then in hook update for exmaple load the default form display and configure it. This is for texfield but have a look at upload widget what settings it has:$form_display->setComponent('myfield', ['type' => 'text_textarea', 'weight' => -10, 'settings' => ['rows' => 3]]);
or just do it manually.