protected function DefaultTableMapping::generateFieldTableName in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php \Drupal\Core\Entity\Sql\DefaultTableMapping::generateFieldTableName()
- 9 core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php \Drupal\Core\Entity\Sql\DefaultTableMapping::generateFieldTableName()
Generates a safe and unambiguous field table name.
The method accounts for a maximum table name length of 64 characters, and takes care of disambiguation.
Parameters
\Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition: The field storage definition.
bool $revision: TRUE for revision table, FALSE otherwise.
Return value
string The final table name.
2 calls to DefaultTableMapping::generateFieldTableName()
- DefaultTableMapping::getDedicatedDataTableName in core/
lib/ Drupal/ Core/ Entity/ Sql/ DefaultTableMapping.php - Generates a table name for a field data table.
- DefaultTableMapping::getDedicatedRevisionTableName in core/
lib/ Drupal/ Core/ Entity/ Sql/ DefaultTableMapping.php - Generates a table name for a field revision archive table.
File
- core/
lib/ Drupal/ Core/ Entity/ Sql/ DefaultTableMapping.php, line 619
Class
- DefaultTableMapping
- Defines a default table mapping class.
Namespace
Drupal\Core\Entity\SqlCode
protected function generateFieldTableName(FieldStorageDefinitionInterface $storage_definition, $revision) {
// The maximum length of an entity type ID is 32 characters.
$entity_type_id = substr($storage_definition
->getTargetEntityTypeId(), 0, EntityTypeInterface::ID_MAX_LENGTH);
$separator = $revision ? '_revision__' : '__';
$table_name = $this->prefix . $entity_type_id . $separator . $storage_definition
->getName();
// Limit the string to 48 characters, keeping a 16 characters margin for db
// prefixes.
if (strlen($table_name) > 48) {
// Use a shorter separator and a hash of the field storage unique
// identifier.
$separator = $revision ? '_r__' : '__';
$field_hash = substr(hash('sha256', $storage_definition
->getUniqueStorageIdentifier()), 0, 10);
$table_name = $this->prefix . $entity_type_id . $separator . $field_hash;
// If the resulting table name is still longer than 48 characters, use the
// following pattern:
// - prefix: max 34 chars;
// - separator: max 4 chars;
// - field_hash: max 10 chars.
if (strlen($table_name) > 48) {
$prefix = substr($this->prefix, 0, 34);
$table_name = $prefix . $separator . $field_hash;
}
}
return $table_name;
}