You are here

user.install in Zircon Profile 8

Same filename and directory in other branches
  1. 8.0 core/modules/user/user.install

Install, update and uninstall functions for the user module.

File

core/modules/user/user.install
View source
<?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_ascii',
        'length' => DRUPAL_EXTENSION_NAME_MAX_LENGTH,
        'not null' => TRUE,
        'default' => '',
      ),
      'name' => array(
        'description' => 'The identifier of the data.',
        'type' => 'varchar_ascii',
        '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');

  // Insert a row for the anonymous user.
  $storage
    ->create(array(
    'uid' => 0,
    'status' => 0,
    'name' => '',
  ))
    ->save();

  // We need some placeholders here as name and mail are unique.
  // 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,
  ))
    ->save();
}

Functions

Namesort descending Description
user_install Implements hook_install().
user_schema Implements hook_schema().