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' => 'string',
'weight' => $key,
);
$view_options = array(
'label' => 'hidden',
'type' => 'string',
'weight' => $key,
);
…
$type = 'image';
$settings = array();
$form_options['type'] = 'image_image';
$view_options['type'] = 'image_image';
…
$fields[$fieldname] = BaseFieldDefinition::create($type)
->setLabel(t($sections['labels'][$key]))
->setDescription(t($sections['descriptions'][$key]))
->setSettings($settings)
->setDisplayOptions('view', $view_options)
->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->getDefinition() (line 256 of core/lib/Drupal/Core/Entity/EntityManager.php).
?
Anyone has a hint? Thank you in advance!