O'Reilly logo

Drupal 8 Module Development by Daniel Sipos

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required