I created a media image field in my custom entity content:
$fields['image'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Promotion image'))
->setDescription(t('Recommended image size is 1600x900 pixels.'))
->setRevisionable(TRUE)
->setTranslatable(TRUE)
->setRequired(FALSE)
->setSetting('target_type', 'media')
->setSetting('handler', 'default:media')
->setSettings([
'handler_settings' => [
'target_bundles' => [
'image' => 'image',
],
'sort' => [
'field' => '_none',
],
'auto_create' => FALSE,
'auto_create_bundle' => '',
],
])
->setCardinality(1)
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setDisplayOptions('form', [
'settings' => [
'entity_browser' => 'image_browser',
'field_widget_display' => 'rendered_entity',
'field_widget_edit' => TRUE,
'field_widget_remove' => TRUE,
'open' => TRUE,
'selection_mode' => 'selection_append',
'field_widget_display_settings' => [
'view_mode' => 'default',
],
'field_widget_replace' => FALSE,
],
'type' => 'entity_browser_entity_reference',
'weight' => 3,
])
->setDisplayOptions('view', [
'label' => 'hidden',
'settings' => [
'target_type' => 'media',
],
'weight' => 3,
]);
Even though the entity itself, and the field are set to translatable
, the ALT and TITLE attributes of the image are not translated.
If I create this field manually in the UI, it works as intended, and gets translated. How could I define this field to be translatable programmatically?