How do I provide a field storage definition for hook_entity_bundle_field_info? The documentation says:


  Bundle fields either have to override an existing base field, or need to provide a field storage definition via hook_entity_field_storage_info() unless they are computed.


How can I do that?

I tried something like this:

/**
 * Implements hook_entity_field_storage_info().
 */
function km_mod_entity_field_storage_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) {
  if ($entity_type-&gt;id() == 'node') {
    $definitions['field_metatags'] = \Drupal\Core\Field\BaseFieldDefinition::create('metatag')
      -&gt;setName('field_metatags')
      -&gt;setLabel(t('Metatags'))
      -&gt;setTranslatable(TRUE)
      -&gt;setCardinality(1)
      -&gt;setTargetEntityTypeId($entity_type-&gt;id());
    return $definitions;
  }
}


/**
 * Implements hook_entity_bundle_field_info().
 */
function km_mod_entity_bundle_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {

  if ($entity_type-&gt;id() === 'node') {
    $fields = [];

    $fields['field_metatags'] = BaseFieldDefinition::create('metatag')
      -&gt;setLabel(t('Metatags'))
      -&gt;setDisplayOptions('view', array(
        'label' =&gt; 'hidden',
        'type' =&gt; 'hidden',
        'weight' =&gt; 0,
      ))
      -&gt;setDisplayOptions('form', array(
        'type' =&gt; 'metatag',
        'weight' =&gt; 50,
      ));

    return $fields;
  }
}


It does not work as intended though. The field does not appear during Form display, and when trying to save:

Drupal\Core\Entity\EntityStorageException: Table mapping contains invalid field field_metatags. in Drupal\Core\Entity\Sql\SqlContentEntityStorage-&gt;save()


I've checked the field storage config yaml (by creating the field manually) and it doesn't really look any difference to how I try to configure it:

uuid: 4c6ecbd5-49b3-4305-8f47-518f76a917f7
langcode: sv
status: true
dependencies:
  module:
    - metatag
    - node
id: node.field_yaay
field_name: field_yaay
entity_type: node
type: metatag
settings: {  }
module: metatag
locked: false
cardinality: 1
translatable: true
indexes: {  }
persist_with_no_fields: false
custom_storage: false


I have run drush entity-updates as well, with no luck.

So what am I doing wrong?
I ran into the same issue. It looks like there might be a problem with Core.

This patch attached to the issue "Hook entity_field_storage_info is broken" fixed things for me.