diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index b00d23b21d3829dbd7f88690dbb1edd88d363f2e..79c310fbd3f12ac932ffdf284bf1579b42076a62 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -965,7 +965,7 @@ function install_base_system(&$install_state) { // Enable the user module so that sessions can be recorded during the // upcoming bootstrap step. - \Drupal::moduleHandler()->install(array('user'), FALSE); + \Drupal::moduleHandler()->install(array('field', 'user'), FALSE); // Save the list of other modules to install for the upcoming tasks. // State can be set to the database now that system.module is installed. diff --git a/core/modules/user/lib/Drupal/user/Tests/UserInstallTest.php b/core/modules/user/lib/Drupal/user/Tests/UserInstallTest.php index 4e54ff85bdc386cbf437075356c10db09a78f34b..5d4114884d211c21b7a0c2701897b24b55e71298 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserInstallTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserInstallTest.php @@ -19,7 +19,7 @@ class UserInstallTest extends DrupalUnitTestBase { * * @var array */ - public static $modules = array('user'); + public static $modules = array('field', 'user'); /** * {@inheritdoc} @@ -51,11 +51,15 @@ public function testUserInstall() { $this->assertFalse(empty($anon->uuid), 'Anon user has a UUID'); $this->assertFalse(empty($admin->uuid), 'Admin user has a UUID'); - $this->assertEqual($anon->langcode, \Drupal::languageManager()->getDefaultLanguage()->id, 'Anon user language is the default.'); - $this->assertEqual($admin->langcode, \Drupal::languageManager()->getDefaultLanguage()->id, 'Admin user language is the default.'); + // Test that the anonymous and administrators languages are equal to the + // site's default language. + $this->assertEqual($anon->langcode, \Drupal::languageManager()->getDefaultLanguage()->id); + $this->assertEqual($admin->langcode, \Drupal::languageManager()->getDefaultLanguage()->id); - $this->assertEqual($admin->status, 1, 'Admin user is active.'); - $this->assertEqual($anon->status, 0, 'Anon user is blocked.'); + // Test that the administrator is active. + $this->assertEqual($admin->status, 1); + // Test that the anonymous user is blocked. + $this->assertEqual($anon->status, 0); } } diff --git a/core/modules/user/lib/Drupal/user/UserStorage.php b/core/modules/user/lib/Drupal/user/UserStorage.php index afd53b3fcea301d11722230a20861e8902c318de..bad10dab1ea8353a100a7c608a7e0d12c52e8009 100644 --- a/core/modules/user/lib/Drupal/user/UserStorage.php +++ b/core/modules/user/lib/Drupal/user/UserStorage.php @@ -99,7 +99,9 @@ function mapFromStorageRecords(array $records) { * {@inheritdoc} */ public function save(EntityInterface $entity) { - if (!$entity->id()) { + // The anonymous user account is saved with the fixed user ID of 0. + // Therefore we need to check for NULL explicitly. + if ($entity->id() === NULL) { $entity->uid->value = $this->database->nextId($this->database->query('SELECT MAX(uid) FROM {users}')->fetchField()); $entity->enforceIsNew(); } diff --git a/core/modules/user/user.info.yml b/core/modules/user/user.info.yml index 45a421a5ade5fa769e9088de5c68340224cfed51..9800f7ff2ac9dc55f50faf6f484174648e364c7c 100644 --- a/core/modules/user/user.info.yml +++ b/core/modules/user/user.info.yml @@ -6,3 +6,7 @@ version: VERSION core: 8.x required: true configure: user.admin_index +# @todo Remove this field dependency +# @see https://drupal.org/node/2116363 +dependencies: + - field diff --git a/core/modules/user/user.install b/core/modules/user/user.install index 97515a251fce1e1a7040f3450a919622f5f4c014..090b235018e369248f2677acf5e9c70d38798d43 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -220,28 +220,27 @@ function user_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. - db_insert('users') - ->fields(array( + $storage + ->create(array( 'uid' => 0, - 'uuid' => \Drupal::service('uuid')->generate(), - 'name' => '', - 'mail' => '', - 'langcode' => \Drupal::languageManager()->getDefaultLanguage()->id, + 'status' => 0, + 'langcode' => $langcode, )) - ->execute(); + ->save(); // We need some placeholders here as name and mail are uniques. // This will be changed by the settings form in the installer. - db_insert('users') - ->fields(array( + $storage + ->create(array( 'uid' => 1, - 'uuid' => \Drupal::service('uuid')->generate(), 'name' => 'placeholder-for-uid-1', 'mail' => 'placeholder-for-uid-1', - 'created' => REQUEST_TIME, - 'status' => 1, - 'langcode' => \Drupal::languageManager()->getDefaultLanguage()->id, + 'langcode' => $langcode, )) - ->execute(); + ->save(); }