This is how i create my field in my Entity content :
$fields['fid'] = BaseFieldDefinition::create('file')
->setLabel(t('Photo'))
->setRequired(false)
->setDescription(t('Product image'))
->setSettings(array(
'upload_location' => 'public://produits/',
'upload_validators' => array(
'file_validate_extensions' => array('png jpg jpeg'),
),
))
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'file',
'weight' => -3,
))
->setDisplayOptions('form', array(
'type' => 'file',
'settings' => array(
'upload_location' => 'public://produits/',
'upload_validators' => array(
'file_validate_extensions' => array('png jpg jpeg'),
),
),
'weight' => -1,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
The field is create in my form but when i try to upload a file :
I got this error :
Only '.txt' extension is authorized
Edit 1 :
In fact my settings are never read, after upload a .txt for test, the directory is wrong.
Any idea about this ?
t()
needs to be in English. You don't use a call liket('La photo de votre product')
.