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', Â Â ...