Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_field_storage_info()
  2. 9 core/lib/Drupal/Core/Entity/entity.api.php \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: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

entity_schema_test_entity_field_storage_info in core/modules/system/tests/modules/entity_schema_test/entity_schema_test.module
Implements hook_entity_field_storage_info().
entity_test_extra_entity_field_storage_info in core/modules/system/tests/modules/entity_test_extra/entity_test_extra.module
Implements hook_entity_field_storage_info().
entity_test_update_entity_field_storage_info in core/modules/system/tests/modules/entity_test_update/entity_test_update.module
Implements hook_entity_field_storage_info().
field_entity_field_storage_info in core/modules/field/field.module
Implements hook_entity_field_storage_info().

File

core/lib/Drupal/Core/Entity/entity.api.php, line 2045
Hooks and documentation related to entities.

Code

function hook_entity_field_storage_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) {
  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);
    $result = [];
    foreach ($field_storages as $field_storage) {
      $result[$field_storage
        ->getName()] = $field_storage;
    }
    return $result;
  }
}