Adding an image base field to custom content entity consider the following situation: I have created a custom content entity with several base fields (string and string_long fields) and it works flawlessly. In addition I want the entity to hold an image field which I defined the same way I did with the other fields:

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {

    …

    $form_options = array(
        'type' =&gt; 'string',
        'weight' =&gt; $key,
    );

    $view_options = array(
        'label' =&gt; 'hidden',
        'type' =&gt; 'string',
        'weight' =&gt; $key,
    );

    …

    $type = 'image';
    $settings = array();
    $form_options['type'] = 'image_image';
    $view_options['type'] = 'image_image';

    …

    $fields[$fieldname] = BaseFieldDefinition::create($type)
        -&gt;setLabel(t($sections['labels'][$key]))
        -&gt;setDescription(t($sections['descriptions'][$key]))
        -&gt;setSettings($settings)
        -&gt;setDisplayOptions('view', $view_options)
        -&gt;setDisplayOptions('form', $form_options);
}


Now, why would I get the errors Notice: Undefined index: target_type in Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::propertyDefinitions() (line 70 of core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php). and Drupal\Component\Plugin\Exception\PluginNotFoundException: The "" entity type does not exist. in Drupal\Core\Entity\EntityManager-&gt;getDefinition() (line 256 of core/lib/Drupal/Core/Entity/EntityManager.php).?

Anyone has a hint?
Thank you in advance!
Looks like you need to specify the target_type.

It should get the default from FileItem::defaultStorageSettings(), I am not sure why that doesn't work.

Unrelated, but note that you should not call t() like that, as it makes it impossible for potx to extract translatable strings from your code. Also, watch out for https://www.drupal.org/node/2363099, you need to update it to use nt() then.

Edit: Turns out, the problem is that the code was using setSettings(), which is considered problematic because it replaces all existing settings, including defaults. Switching to setSetting() for specific settings should solve it.