function hook_entity_field_storage_info
Provides field storage definitions for a content entity type.
Field storage definitions returned by this hook must run through the regular field storage life-cycle operations: they need to be properly installed, updated, and uninstalled. This would typically be done through the Entity Update API provided by the entity definition update manager.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition.
Return value
\Drupal\Core\Field\FieldStorageDefinitionInterface[] An array of field storage definitions, keyed by field name.
See also
hook_entity_field_storage_info_alter()
\Drupal\Core\Field\FieldStorageDefinitionInterface
\Drupal\Core\Entity\EntityFieldManagerInterface::getFieldStorageDefinitions()
\Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface
https://www.drupal.org/node/3034742
Related topics
4 functions implement hook_entity_field_storage_info()
Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.
- EntitySchemaTestHooks::entityFieldStorageInfo in core/modules/ system/ tests/ modules/ entity_schema_test/ src/ Hook/ EntitySchemaTestHooks.php 
- Implements hook_entity_field_storage_info().
- EntityTestExtraHooks::entityFieldStorageInfo in core/modules/ system/ tests/ modules/ entity_test_extra/ src/ Hook/ EntityTestExtraHooks.php 
- Implements hook_entity_field_storage_info().
- EntityTestUpdateHooks::entityFieldStorageInfo in core/modules/ system/ tests/ modules/ entity_test_update/ src/ Hook/ EntityTestUpdateHooks.php 
- Implements hook_entity_field_storage_info().
- FieldHooks::entityFieldStorageInfo in core/modules/ field/ src/ Hook/ FieldHooks.php 
- Implements hook_entity_field_storage_info().
File
- 
              core/lib/ Drupal/ Core/ Entity/ entity.api.php, line 2094 
Code
function hook_entity_field_storage_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) : array {
  $result = [];
  if (\Drupal::entityTypeManager()->getStorage($entity_type->id()) instanceof DynamicallyFieldableEntityStorageInterface) {
    // Query by filtering on the ID as this is more efficient than filtering
    // on the entity_type property directly.
    $ids = \Drupal::entityQuery('field_storage_config')->condition('id', $entity_type->id() . '.', 'STARTS_WITH')
      ->execute();
    // Fetch all fields and key them by field name.
    $field_storages = FieldStorageConfig::loadMultiple($ids);
    foreach ($field_storages as $field_storage) {
      $result[$field_storage->getName()] = $field_storage;
    }
  }
  return $result;
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
