summaryrefslogtreecommitdiffstats
path: root/core/modules/user/user.install
blob: eca1692cbec69fa13c3c3b291398b8cfc7e6eb19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php

/**
 * @file
 * Install, update and uninstall functions for the user module.
 */

/**
 * Implements hook_schema().
 */
function user_schema() {
  $schema['users_data'] = array(
    'description' => 'Stores module data as key/value pairs per user.',
    'fields' => array(
      'uid' => array(
        'description' => 'Primary key: {users}.uid for user.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'module' => array(
        'description' => 'The name of the module declaring the variable.',
        'type' => 'varchar',
        'length' => DRUPAL_EXTENSION_NAME_MAX_LENGTH,
        'not null' => TRUE,
        'default' => '',
      ),
      'name' => array(
        'description' => 'The identifier of the data.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'value' => array(
        'description' => 'The value.',
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
      ),
      'serialized' => array(
        'description' => 'Whether value is serialized.',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('uid', 'module', 'name'),
    'indexes' => array(
      'module' => array('module'),
      'name' => array('name'),
    ),
    'foreign keys' => array(
      'uid' => array('users' => 'uid'),
    ),
  );

  return $schema;
}

/**
 * Implements hook_install().
 */
function user_install() {
  $storage = \Drupal::entityManager()->getStorage('user');
  // @todo Rely on the default value for langcode in
  //   https://drupal.org/node/1966436
  $langcode = \Drupal::languageManager()->getDefaultLanguage()->id;
  // Insert a row for the anonymous user.
  $storage
    ->create(array(
      'uid' => 0,
      'status' => 0,
      'langcode' => $langcode,
    ))
    ->save();

  // We need some placeholders here as name and mail are uniques.
  // This will be changed by the settings form in the installer.
  $storage
    ->create(array(
      'uid' => 1,
      'name' => 'placeholder-for-uid-1',
      'mail' => 'placeholder-for-uid-1',
      'status' => TRUE,
      'langcode' => $langcode,
    ))
    ->save();
}