diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index f75afab3cf..7087394c1d 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -2249,10 +2249,9 @@ protected function getDedicatedTableSchema(FieldStorageDefinitionInterface $stor } else { $id_settings = $id_definition->getSettings(); - $max_length = array_key_exists('max_length', $id_settings) ? $id_settings['max_length'] : 128; - $is_ascii = array_key_exists('is_ascii', $id_settings) ? $id_settings['is_ascii'] : TRUE; + $max_length = array_key_exists('max_length', $id_settings) ? $id_settings['max_length'] : 255; $id_schema = [ - 'type' => $is_ascii ? 'varchar_ascii' : 'varchar', + 'type' => 'varchar', 'length' => $max_length, 'not null' => TRUE, 'description' => 'The entity id this data is attached to', diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php index 0bf634ea5e..9e65e19c79 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php @@ -133,17 +133,32 @@ public static function schema(FieldStorageDefinitionInterface $field_definition) ]; } else { + $id_key = $target_type_info->getKey('id'); + $entity_field_manager = \Drupal::service('entity_field.manager'); + $base_fields = $entity_field_manager->getBaseFieldDefinitions($target_type); + $id_field_definition = $base_fields[$id_key]; + $id_settings = $id_field_definition->getItemDefinition()->getSettings(); + if ($target_type_info->getBundleOf()) { + // If the target entities act as bundles for another entity type, + // their IDs should not exceed the maximum length for bundles. + $column_max_length = EntityTypeInterface::BUNDLE_MAX_LENGTH; + } + elseif (array_key_exists('max_length', $id_settings)) { + $column_max_length = $id_settings['max_length']; + } + else { + $column_max_length = 255; + } $columns = [ 'target_id' => [ 'description' => 'The ID of the target entity.', - 'type' => 'varchar_ascii', - // If the target entities act as bundles for another entity type, - // their IDs should not exceed the maximum length for bundles. - 'length' => $target_type_info->getBundleOf() ? EntityTypeInterface::BUNDLE_MAX_LENGTH : 255, + 'type' => 'varchar', + 'length' => $column_max_length, ], ]; } + $schema = [ 'columns' => $columns, 'indexes' => [