Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / user / src / UserStorageSchema.php
1 <?php
2
3 namespace Drupal\user;
4
5 use Drupal\Core\Entity\ContentEntityTypeInterface;
6 use Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema;
7 use Drupal\Core\Field\FieldStorageDefinitionInterface;
8
9 /**
10  * Defines the user schema handler.
11  */
12 class UserStorageSchema extends SqlContentEntityStorageSchema {
13
14   /**
15    * {@inheritdoc}
16    */
17   protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) {
18     $schema = parent::getEntitySchema($entity_type, $reset);
19
20     $schema['users_field_data']['unique keys'] += [
21       'user__name' => ['name', 'langcode'],
22     ];
23
24     return $schema;
25   }
26
27   /**
28    * {@inheritdoc}
29    */
30   protected function processIdentifierSchema(&$schema, $key) {
31     // The "users" table does not use serial identifiers.
32     if ($key != $this->entityType->getKey('id')) {
33       parent::processIdentifierSchema($schema, $key);
34     }
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, $table_name, array $column_mapping) {
41     $schema = parent::getSharedTableFieldSchema($storage_definition, $table_name, $column_mapping);
42     $field_name = $storage_definition->getName();
43
44     if ($table_name == 'users_field_data') {
45       switch ($field_name) {
46         case 'name':
47           // Improves the performance of the user__name index defined
48           // in getEntitySchema().
49           $schema['fields'][$field_name]['not null'] = TRUE;
50           // Make sure the field is no longer than 191 characters so we can
51           // add a unique constraint in MySQL.
52           $schema['fields'][$field_name]['length'] = USERNAME_MAX_LENGTH;
53           break;
54
55         case 'mail':
56           $this->addSharedTableFieldIndex($storage_definition, $schema);
57           break;
58
59         case 'access':
60         case 'created':
61           $this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);
62           break;
63       }
64     }
65
66     return $schema;
67   }
68
69 }