W3cubDocs

/Drupal 8

function hook_entity_field_storage_info

hook_entity_field_storage_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type)

Provides field storage definitions for a content entity type.

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\EntityManagerInterface::getFieldStorageDefinitions()

Related topics

Hooks
Define functions that alter the behavior of Drupal core.

File

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

Code

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

    return $result;
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!entity.api.php/function/hook_entity_field_storage_info/8.1.x