function hook_entity_field_storage_info
Same name in other branches
- 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_field_storage_info()
- 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_field_storage_info()
- 10 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
3 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().
File
-
core/
lib/ Drupal/ Core/ Entity/ entity.api.php, line 2065
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.