function SqlContentEntityStorageSchema::getFieldSchemaData

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::getFieldSchemaData()
  2. 8.9.x core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::getFieldSchemaData()
  3. 11.x core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::getFieldSchemaData()

Gets field schema data for the given key.

Parameters

string $field_name: The name of the field.

array $field_schema: The schema of the field.

string[] $column_mapping: A mapping of field column names to database column names.

string $schema_key: The type of schema data. Either 'indexes' or 'unique keys'.

Return value

array The schema definition for the specified key.

2 calls to SqlContentEntityStorageSchema::getFieldSchemaData()
SqlContentEntityStorageSchema::getFieldIndexes in core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php
Gets an index schema array for a given field.
SqlContentEntityStorageSchema::getFieldUniqueKeys in core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php
Gets a unique key schema array for a given field.

File

core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php, line 1135

Class

SqlContentEntityStorageSchema
Defines a schema handler that supports revisionable, translatable entities.

Namespace

Drupal\Core\Entity\Sql

Code

protected function getFieldSchemaData($field_name, array $field_schema, array $column_mapping, $schema_key) {
    $data = [];
    $entity_type_id = $this->entityType
        ->id();
    foreach ($field_schema[$schema_key] as $key => $columns) {
        // To avoid clashes with entity-level indexes or unique keys we use
        // "{$entity_type_id}_field__" as a prefix instead of just
        // "{$entity_type_id}__". We additionally namespace the specifier by the
        // field name to avoid clashes when multiple fields of the same type are
        // added to an entity type.
        $real_key = $this->getFieldSchemaIdentifierName($entity_type_id, $field_name, $key);
        foreach ($columns as $column) {
            // Allow for indexes and unique keys to specified as an array of column
            // name and length.
            if (is_array($column)) {
                [
                    $column_name,
                    $length,
                ] = $column;
                $data[$real_key][] = [
                    $column_mapping[$column_name],
                    $length,
                ];
            }
            else {
                $data[$real_key][] = $column_mapping[$column];
            }
        }
    }
    return $data;
}

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