function user_update_8001

Splits {users}.language field to langcode and preferred_langcode.

See also

http://drupal.org/node/1454538

Related topics

File

drupal/core/modules/user/user.install, line 413
Install, update and uninstall functions for the user module.

Code

function user_update_8001() {

  // The former language field is the language preference of the user. Rename
  // this to preferred_langcode in order to distinguish it from the langcode
  // field common to all entity types, used for identifying the language of the
  // entity itself.
  $preferred_langcode_field = array(
    'type' => 'varchar',
    'length' => 12,
    'not null' => TRUE,
    'default' => '',
    'description' => 'The {language}.langcode that the user prefers for receiving emails and viewing the site.',
  );
  db_change_field('users', 'language', 'preferred_langcode', $preferred_langcode_field);

  // Add the langcode field.
  $langcode_field = array(
    'type' => 'varchar',
    'length' => 12,
    'not null' => TRUE,
    'default' => '',
    'description' => "The {language}.langcode of the user's profile.",
  );
  db_add_field('users', 'langcode', $langcode_field);

  // Since distinguishing the language of the user entity from the user's
  // preferred language is a new feature in Drupal 8, assume that for updated
  // sites, existing user entities are in the user's preferred language.
  db_update('users')
    ->expression('langcode', 'preferred_langcode')
    ->execute();
}