You are here

protected function EntityFieldManager::buildFieldStorageDefinitions in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/EntityFieldManager.php \Drupal\Core\Entity\EntityFieldManager::buildFieldStorageDefinitions()
  2. 9 core/lib/Drupal/Core/Entity/EntityFieldManager.php \Drupal\Core\Entity\EntityFieldManager::buildFieldStorageDefinitions()

Builds field storage definitions for an entity type.

Parameters

string $entity_type_id: The entity type ID. Only entity types that implement \Drupal\Core\Entity\FieldableEntityInterface are supported

Return value

\Drupal\Core\Field\FieldStorageDefinitionInterface[] An array of field storage definitions, keyed by field name.

File

core/lib/Drupal/Core/Entity/EntityFieldManager.php, line 576

Class

EntityFieldManager
Manages the discovery of entity fields.

Namespace

Drupal\Core\Entity

Code

protected function buildFieldStorageDefinitions($entity_type_id) {
  $entity_type = $this->entityTypeManager
    ->getDefinition($entity_type_id);
  $field_definitions = [];

  // Retrieve base field definitions from modules.
  $this->moduleHandler
    ->invokeAllWith('entity_field_storage_info', function (callable $hook, string $module) use (&$field_definitions, $entity_type, $entity_type_id) {
    $module_definitions = $hook($entity_type) ?? [];

    // Ensure the provider key actually matches the name of the provider
    // defining the field.
    foreach ($module_definitions as $field_name => $definition) {

      // @todo Remove this check once FieldDefinitionInterface exposes a
      //   proper provider setter. See https://www.drupal.org/node/2225961.
      if ($definition instanceof BaseFieldDefinition) {
        $definition
          ->setProvider($module);
        $definition
          ->setName($field_name);
        $definition
          ->setTargetEntityTypeId($entity_type_id);
      }
      $field_definitions[$field_name] = $definition;
    }
  });

  // Invoke alter hook.
  $this->moduleHandler
    ->alter('entity_field_storage_info', $field_definitions, $entity_type);
  return $field_definitions;
}