Using the File and Image fields
In order to demonstrate how to work with managed files, we will go back to our product entity importer and bring in some images for each product. However, in order to store them, we need to create a field on the Product entity. This will be an Image
field.
Instead of creating this field through the UI and attaching it to a bundle, let’s do it the programmatic way and make it a base field (available on all bundles). We won’t need to do anything complex; for now, we are only interested in a basic field that we can use to store the images we bring in from the remote API. It can look something like this:
$fields['image'] = BaseFieldDefinition::create('image') ->setLabel(t('Image')) ->setDescription(t('The product image.')) ->setDisplayOptions('form', array( 'type' => 'image_image', ...