You are here

protected function SqlContentEntityStorageSchema::addSharedTableFieldUniqueKey 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::addSharedTableFieldUniqueKey()

Adds a unique key for the specified field to the given schema definition.

Also adds a 'not null' constraint, because many databases do not reliably support unique keys on null columns.

Parameters

\Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition: The storage definition of the field to which to add a unique key.

array $schema: A reference to the schema array to be updated.

File

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

Class

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

Namespace

Drupal\Core\Entity\Sql

Code

protected function addSharedTableFieldUniqueKey(FieldStorageDefinitionInterface $storage_definition, &$schema) {
  $name = $storage_definition
    ->getName();
  $real_key = $this
    ->getFieldSchemaIdentifierName($storage_definition
    ->getTargetEntityTypeId(), $name);
  $schema['unique keys'][$real_key] = [
    $name,
  ];
  $schema['fields'][$name]['not null'] = TRUE;
}