function EntityFieldManager::buildFieldStorageDefinitions

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityFieldManager.php \Drupal\Core\Entity\EntityFieldManager::buildFieldStorageDefinitions()
  2. 8.9.x core/lib/Drupal/Core/Entity/EntityFieldManager.php \Drupal\Core\Entity\EntityFieldManager::buildFieldStorageDefinitions()
  3. 11.x 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.

1 call to EntityFieldManager::buildFieldStorageDefinitions()
EntityFieldManager::getFieldStorageDefinitions in core/lib/Drupal/Core/Entity/EntityFieldManager.php

File

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

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/2346329.
            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;
}

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