I'm trying to create a custom field for my entity (entity A). It will hold custom entity reference, let's say entity B, with another field associated (integer).
I want to create associations entity A -> [ (entityB, 10), (entityB, 5), ...].
I followed this thread. I copied the code, just changed target type for entity B and string to integer.
The field is rendered fine - entity B with autocomplete, search works as expected. An integer field, works as expected.
But the entities are not saved, nor do I see any table in database where they could be saved. Also the isEmpty() function always returns true, like nothing is associated to this field. This is field definition:
$fields['entityb'] = BaseFieldDefinition::create('enetity_b_type_id')
->setLabel(t('Entity b'))
->setDescription(t('My field'))
->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
->setDisplayOptions('form', [
'weight' => 8,
'type' => 'entity_reference_autocomplete'
])
->setDisplayOptions('view', [
'type' => 'string',
'weight' => 8,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
Do I need to define the storage in some yml file? I cannot find any recipe for Drupal for achieving this. Is there any other approach than custom widget?