function hook_entity_field_storage_info

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_field_storage_info()
  2. 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_field_storage_info()
  3. 11.x 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

8 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().
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().

... See full list

File

core/lib/Drupal/Core/Entity/entity.api.php, line 2062

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;
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.