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. 10 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

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().
1 invocation of hook_entity_field_storage_info()
EntityFieldManager::buildFieldStorageDefinitions in core/lib/Drupal/Core/Entity/EntityFieldManager.php
Builds field storage definitions for an entity type.

File

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

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.