Change record status: 
Project: 
Introduced in branch: 
8.8.x
Introduced in version: 
8.0.0-ALPHA1
Description: 

A new \Drupal\Core\Field\FieldStorageDefinition class is added to the core so that field storage definitions can be defined in hook_entity_field_storage_info() e.g.


/**
 * Implements hook_entity_field_storage_info().
 */
function my_module_entity_field_storage_info(EntityTypeInterface $entity_type) {
  if ($entity_type->id() == 'my_module_entity') {
    $definitions['custom_bundle_field'] = FieldStorageDefinition::create('string')
      ->setName('custom_bundle_field')
      ->setLabel(t('A custom bundle field'))
      ->setRevisionable(TRUE)
      ->setTargetEntityTypeId($entity_type->id());
    return $definitions;
  }
}

And then in it can be used in hook_entity_bundle_field_info() to add custom_bundle_field to any bundle.


/**
 * Implements hook_entity_bundle_field_info().
 */
function my_module_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle) {
  if ($entity_type->id() == 'my_module_entity' && $bundle == 'custom') {
    /** @var \Drupal\Core\Field\FieldStorageDefinitionInterface $custom_bundle_field_storage */
    $custom_bundle_field_storage = my_module_entity_field_storage_info($entity_type)['custom_bundle_field'];
    $definitions[$custom_bundle_field_storage->getName()] = FieldDefinition::createFromFieldStorageDefinition($custom_bundle_field_storage);
    return $definitions;
  }
}
Impacts: 
Module developers