You are here

protected function SqlContentEntityStorageSchema::getFieldSchemaIdentifierName in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::getFieldSchemaIdentifierName()
  2. 10 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::getFieldSchemaIdentifierName()

Generates a safe schema identifier (name of an index, column name etc.).

Parameters

string $entity_type_id: The ID of the entity type.

string $field_name: The name of the field.

string|null $key: (optional) A further key to append to the name.

Return value

string The field identifier name.

5 calls to SqlContentEntityStorageSchema::getFieldSchemaIdentifierName()
SqlContentEntityStorageSchema::addSharedTableFieldForeignKey in core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php
Adds a foreign key for the specified field to the given schema definition.
SqlContentEntityStorageSchema::addSharedTableFieldIndex in core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php
Adds an index for the specified field to the given schema definition.
SqlContentEntityStorageSchema::addSharedTableFieldUniqueKey in core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php
Adds a unique key for the specified field to the given schema definition.
SqlContentEntityStorageSchema::getEntitySchemaData in core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php
Gets entity schema definitions for index and key definitions.
SqlContentEntityStorageSchema::getFieldSchemaData in core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php
Gets field schema data for the given key.

File

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

Class

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

Namespace

Drupal\Core\Entity\Sql

Code

protected function getFieldSchemaIdentifierName($entity_type_id, $field_name, $key = NULL) {
  $real_key = isset($key) ? "{$entity_type_id}_field__{$field_name}__{$key}" : "{$entity_type_id}_field__{$field_name}";

  // Limit the string to 48 characters, keeping a 16 characters margin for db
  // prefixes.
  if (strlen($real_key) > 48) {

    // Use a shorter separator, a truncated entity_type, and a hash of the
    // field name.
    // Truncate to the same length for the current and revision tables.
    $entity_type = substr($entity_type_id, 0, 36);
    $field_hash = substr(hash('sha256', $real_key), 0, 10);
    $real_key = $entity_type . '__' . $field_hash;
  }
  return $real_key;
}