Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
fixed typos, added tag
Link
Pierre.Vriens
  • 36k
  • 40
  • 50
  • 182

How to create an 'Upload a file' field in Drupal 8?

How to create an 'Upload a file' field in DruplaDrupal 8?

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 somasome 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

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

How to create an 'Upload a file' field in Drupla 8?

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 soma 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

How to create an 'Upload a file' field in Drupal 8?

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

Source Link
badm
  • 313
  • 1
  • 5
  • 18

How to create an 'Upload a file' field in Drupla 8?

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 soma 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