diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc index e3a7d7c..a3f355f 100644 --- a/core/modules/file/file.field.inc +++ b/core/modules/file/file.field.inc @@ -249,7 +249,7 @@ function file_field_update(EntityInterface $entity, $field, $instance, $langcode } // Compare the original field values with the ones that are being saved. - $original = $entity->original; + $original = $entity->original->getBCEntity(); $original_fids = array(); if (!empty($original->{$field['field_name']}[$langcode])) { foreach ($original->{$field['field_name']}[$langcode] as $original_item) { diff --git a/core/modules/node/tests/modules/node_access_test/node_access_test.module b/core/modules/node/tests/modules/node_access_test/node_access_test.module index 66c6b59..38ee65c 100644 --- a/core/modules/node/tests/modules/node_access_test/node_access_test.module +++ b/core/modules/node/tests/modules/node_access_test/node_access_test.module @@ -17,13 +17,13 @@ function node_access_test_node_grants($account, $op) { $grants = array(); // First grant a grant to the author for own content. - $grants['node_access_test_author'] = array($account->uid); + $grants['node_access_test_author'] = array($account->id()); if ($op == 'view' && user_access('node test view', $account)) { $grants['node_access_test'] = array(8888, 8889); } $no_access_uid = state()->get('node_access_test.no_access_uid') ?: 0; - if ($op == 'view' && $account->uid == $no_access_uid) { + if ($op == 'view' && $account->id() == $no_access_uid) { $grants['node_access_all'] = array(0); } return $grants; diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 4fc06f7..93bf344 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2609,6 +2609,8 @@ function system_form_user_register_form_alter(&$form, &$form_state) { */ function system_user_presave($account) { $config = config('system.timezone'); + debug(get_class($account)); + debug(print_r($account->timezone, TRUE)); if ($config->get('user.configurable') && empty($account->timezone) && !$config->get('user.default')) { $account->timezone = $config->get('default'); } diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationWorkflowsTest.php b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationWorkflowsTest.php index 9957552..741b806 100644 --- a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationWorkflowsTest.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationWorkflowsTest.php @@ -7,7 +7,7 @@ namespace Drupal\translation_entity\Tests; -use Drupal\user\Plugin\Core\Entity\User; +use Drupal\Core\Entity\EntityInterface; /** * Tests entity translation workflows. @@ -113,7 +113,7 @@ function testWorkflows() { * The an associative array with the operation name as key and the expected * status as value. */ - protected function assertWorkflows(User $user, $expected_status) { + protected function assertWorkflows(EntityInterface $user, $expected_status) { $default_langcode = $this->langcodes[0]; $languages = language_list(); $args = array('@user_label' => $user->name); diff --git a/core/modules/user/lib/Drupal/user/AccountFormController.php b/core/modules/user/lib/Drupal/user/AccountFormController.php index 8f2f0c5..32fc112 100644 --- a/core/modules/user/lib/Drupal/user/AccountFormController.php +++ b/core/modules/user/lib/Drupal/user/AccountFormController.php @@ -146,7 +146,7 @@ public function form(array $form, array &$form_state, EntityInterface $account) $form['account']['roles'] = array( '#type' => 'checkboxes', '#title' => t('Roles'), - '#default_value' => (!$register && isset($account->roles) ? array_keys($account->roles) : array()), + '#default_value' => (!$register ? $account->roles : array()), '#options' => $roles, '#access' => $roles && user_access('administer permissions'), DRUPAL_AUTHENTICATED_RID => $checkbox_authenticated, @@ -225,6 +225,20 @@ public function form(array $form, array &$form_state, EntityInterface $account) } /** + * Overrides Drupal\Core\Entity\EntityFormController::buildEntity(). + */ + public function buildEntity(array $form, array &$form_state) { + // Change the roles array to a list of enabled roles. + // @todo: Move this to an value callback on the form element. + if (empty($this->roles_filtered)) { + $form_state['values']['roles'] = array_keys(array_filter($form_state['values']['roles'])); + $this->roles_filtered = TRUE; + } + debug($form_state['values']); + return parent::buildEntity($form, $form_state); + } + + /** * Overrides Drupal\Core\Entity\EntityFormController::submit(). */ public function validate(array $form, array &$form_state) { diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/filter/Name.php b/core/modules/user/lib/Drupal/user/Plugin/views/filter/Name.php index 9d95b65..e46265b 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/filter/Name.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/filter/Name.php @@ -29,8 +29,8 @@ function value_form(&$form, &$form_state) { if ($this->value) { $result = entity_load_multiple_by_properties('user', array('uid' => $this->value)); foreach ($result as $account) { - if ($account->uid) { - $values[] = $account->name; + if ($account->id()) { + $values[] = $account->name->value; } else { $values[] = 'Anonymous'; // Intentionally NOT translated. @@ -133,8 +133,8 @@ function validate_user_strings(&$form, $values) { $result = entity_load_multiple_by_properties('user', array('name' => $args)); foreach ($result as $account) { - unset($missing[strtolower($account->name)]); - $uids[] = $account->uid; + unset($missing[strtolower($account->name->value)]); + $uids[] = $account->id(); } if ($missing) { @@ -159,10 +159,10 @@ public function adminSummary() { $result = entity_load_multiple_by_properties('user', array('uid' => $this->value)); foreach ($result as $account) { if ($account->uid) { - $this->value_options[$account->uid] = $account->name; + $this->value_options[$account->id()] = $account->label(); } else { - $this->value_options[$account->uid] = 'Anonymous'; // Intentionally NOT translated. + $this->value_options[$account->id()] = 'Anonymous'; // Intentionally NOT translated. } } } diff --git a/core/modules/user/lib/Drupal/user/ProfileFormController.php b/core/modules/user/lib/Drupal/user/ProfileFormController.php index bc36fbd..c2b139d 100644 --- a/core/modules/user/lib/Drupal/user/ProfileFormController.php +++ b/core/modules/user/lib/Drupal/user/ProfileFormController.php @@ -30,15 +30,6 @@ protected function actions(array $form, array &$form_state) { } /** - * Overrides Drupal\Core\Entity\EntityFormController::buildEntity(). - */ - public function buildEntity(array $form, array &$form_state) { - // Change the roles array to a list of enabled roles. - $form_state['values']['roles'] = array_keys(array_filter($form_state['values']['roles'])); - return parent::buildEntity($form, $form_state); - } - - /** * Overrides Drupal\Core\Entity\EntityFormController::submit(). */ public function submit(array $form, array &$form_state) { diff --git a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php index 38ca376..a1c23e5 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php @@ -45,7 +45,7 @@ function testRegistrationWithEmailVerification() { $this->assertText(t('A welcome message with further instructions has been sent to your e-mail address.'), 'User registered successfully.'); $accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail)); $new_user = reset($accounts); - $this->assertTrue($new_user->status, 'New account is active after registration.'); + $this->assertTrue($new_user->status->value, 'New account is active after registration.'); // Allow registration by site visitors, but require administrator approval. $config->set('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)->save(); @@ -56,7 +56,7 @@ function testRegistrationWithEmailVerification() { $this->container->get('plugin.manager.entity')->getStorageController('user')->resetCache(); $accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail)); $new_user = reset($accounts); - $this->assertFalse($new_user->status, 'New account is blocked until approved by an administrator.'); + $this->assertFalse($new_user->status->value, 'New account is blocked until approved by an administrator.'); } function testRegistrationWithoutEmailVerification() { @@ -114,7 +114,7 @@ function testRegistrationWithoutEmailVerification() { $edit = array( 'status' => 1, ); - $this->drupalPost('user/' . $new_user->uid . '/edit', $edit, t('Save')); + $this->drupalPost('user/' . $new_user->id() . '/edit', $edit, t('Save')); $this->drupalLogout(); // Login after administrator approval. @@ -177,16 +177,17 @@ function testRegistrationDefaultValues() { // Check user fields. $accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail)); $new_user = reset($accounts); - $this->assertEqual($new_user->name, $name, 'Username matches.'); - $this->assertEqual($new_user->mail, $mail, 'E-mail address matches.'); - $this->assertEqual($new_user->theme, '', 'Correct theme field.'); - $this->assertEqual($new_user->signature, '', 'Correct signature field.'); - $this->assertTrue(($new_user->created > REQUEST_TIME - 20 ), 'Correct creation time.'); - $this->assertEqual($new_user->status, $config_user_settings->get('register') == USER_REGISTER_VISITORS ? 1 : 0, 'Correct status field.'); - $this->assertEqual($new_user->timezone, $config_system_timezone->get('default'), 'Correct time zone field.'); - $this->assertEqual($new_user->langcode, language_default()->langcode, 'Correct language field.'); - $this->assertEqual($new_user->preferred_langcode, language_default()->langcode, 'Correct preferred language field.'); - $this->assertEqual($new_user->init, $mail, 'Correct init field.'); + $this->assertEqual($new_user->name->value, $name, 'Username matches.'); + $this->assertEqual($new_user->mail->value, $mail, 'E-mail address matches.'); + $this->assertEqual($new_user->theme->value, '', 'Correct theme field.'); + $this->assertEqual($new_user->signature->value, '', 'Correct signature field.'); + $this->assertTrue(($new_user->created->value > REQUEST_TIME - 20 ), 'Correct creation time.'); + $this->assertEqual($new_user->status->value, $config_user_settings->get('register') == USER_REGISTER_VISITORS ? 1 : 0, 'Correct status field.'); + debug($new_user->timezone->value); + $this->assertEqual($new_user->timezone->value, $config_system_timezone->get('default'), 'Correct time zone field.'); + $this->assertEqual($new_user->langcode->value, language_default()->langcode, 'Correct language field.'); + $this->assertEqual($new_user->preferred_langcode->value, language_default()->langcode, 'Correct preferred language field.'); + $this->assertEqual($new_user->init->value, $mail, 'Correct init field.'); } /** @@ -240,7 +241,7 @@ function testRegistrationWithUserFields() { // Check user fields. $accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail)); $new_user = reset($accounts); - $this->assertEqual($new_user->test_user_field[LANGUAGE_NOT_SPECIFIED][0]['value'], $value, 'The field value was correclty saved.'); + $this->assertEqual($new_user->test_user_field->value, $value, 'The field value was correclty saved.'); // Check that the 'add more' button works. $field['cardinality'] = FIELD_CARDINALITY_UNLIMITED; @@ -268,9 +269,9 @@ function testRegistrationWithUserFields() { // Check user fields. $accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail)); $new_user = reset($accounts); - $this->assertEqual($new_user->test_user_field[LANGUAGE_NOT_SPECIFIED][0]['value'], $value, format_string('@js : The field value was correclty saved.', array('@js' => $js))); - $this->assertEqual($new_user->test_user_field[LANGUAGE_NOT_SPECIFIED][1]['value'], $value + 1, format_string('@js : The field value was correclty saved.', array('@js' => $js))); - $this->assertEqual($new_user->test_user_field[LANGUAGE_NOT_SPECIFIED][2]['value'], $value + 2, format_string('@js : The field value was correclty saved.', array('@js' => $js))); + $this->assertEqual($new_user->test_user_field[0]->value, $value, format_string('@js : The field value was correclty saved.', array('@js' => $js))); + $this->assertEqual($new_user->test_user_field[1]->value, $value + 1, format_string('@js : The field value was correclty saved.', array('@js' => $js))); + $this->assertEqual($new_user->test_user_field[2]->value, $value + 2, format_string('@js : The field value was correclty saved.', array('@js' => $js))); } } } diff --git a/core/modules/user/lib/Drupal/user/Tests/UserRolesAssignmentTest.php b/core/modules/user/lib/Drupal/user/Tests/UserRolesAssignmentTest.php index 349b2a9..e612374 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserRolesAssignmentTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserRolesAssignmentTest.php @@ -94,10 +94,10 @@ function testCreateUserWithRole() { private function userLoadAndCheckRoleAssigned($account, $rid, $is_assigned = TRUE) { $account = user_load($account->uid, TRUE); if ($is_assigned) { - $this->assertTrue(array_key_exists($rid, $account->roles), 'The role is present in the user object.'); + $this->assertTrue(array_search($rid, $account->roles), 'The role is present in the user object.'); } else { - $this->assertFalse(array_key_exists($rid, $account->roles), 'The role is not present in the user object.'); + $this->assertFalse(array_search($rid, $account->roles), 'The role is not present in the user object.'); } } } diff --git a/core/modules/user/lib/Drupal/user/Tests/Views/AccessTestBase.php b/core/modules/user/lib/Drupal/user/Tests/Views/AccessTestBase.php index 5455eaa..33cad6e 100644 --- a/core/modules/user/lib/Drupal/user/Tests/Views/AccessTestBase.php +++ b/core/modules/user/lib/Drupal/user/Tests/Views/AccessTestBase.php @@ -54,11 +54,11 @@ protected function setUp() { $this->adminUser = $this->drupalCreateUser(array('access all views')); $this->webUser = $this->drupalCreateUser(); - $this->webRole = current($this->webUser->roles); + $this->webRole = $this->webUser->roles[0]; $this->normalRole = $this->drupalCreateRole(array()); $this->normalUser = $this->drupalCreateUser(array('views_test_data test permission')); - $this->normalUser->roles[$this->normalRole] = $this->normalRole; + $this->normalUser->getOriginalEntity()->roles[2] = $this->normalRole; // @todo when all the plugin information is cached make a reset function and // call it here. } diff --git a/core/modules/user/lib/Drupal/user/Tests/Views/HandlerFieldRoleTest.php b/core/modules/user/lib/Drupal/user/Tests/Views/HandlerFieldRoleTest.php index 55ec424..7c70baa 100644 --- a/core/modules/user/lib/Drupal/user/Tests/Views/HandlerFieldRoleTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/Views/HandlerFieldRoleTest.php @@ -41,9 +41,9 @@ public function testRole() { $this->drupalCreateRole(array('access content'), $rolename_not_assigned, $rolename_not_assigned); // Add roles to user 1. - $user = user_load(1); - $user->roles[$rid_a] = $rolename_a; - $user->roles[$rid_b] = $rolename_b; + $user = entity_load('user', 1); + $user->roles[1]->value = $rolename_a; + $user->roles[2]->value = $rolename_b; $user->save(); $view = views_get_view('test_views_handler_field_role'); diff --git a/core/modules/user/lib/Drupal/user/UserStorageController.php b/core/modules/user/lib/Drupal/user/UserStorageController.php index 20978c8..fdb7056 100644 --- a/core/modules/user/lib/Drupal/user/UserStorageController.php +++ b/core/modules/user/lib/Drupal/user/UserStorageController.php @@ -26,17 +26,17 @@ function attachLoad(&$queried_users, $load_revision = FALSE) { foreach ($queried_users as $key => $record) { $queried_users[$key]->roles = array(); if ($record->uid) { - $queried_users[$record->uid]->roles[DRUPAL_AUTHENTICATED_RID] = DRUPAL_AUTHENTICATED_RID; + $queried_users[$record->uid]->roles[] = DRUPAL_AUTHENTICATED_RID; } else { - $queried_users[$record->uid]->roles[DRUPAL_ANONYMOUS_RID] = DRUPAL_ANONYMOUS_RID; + $queried_users[$record->uid]->roles[] = DRUPAL_ANONYMOUS_RID; } } // Add any additional roles from the database. $result = db_query('SELECT rid, uid FROM {users_roles} WHERE uid IN (:uids)', array(':uids' => array_keys($queried_users))); foreach ($result as $record) { - $queried_users[$record->uid]->roles[$record->rid] = $record->rid; + $queried_users[$record->uid]->roles[] = $record->rid; } // Call the default attachLoad() method. This will add fields and call