Commit c02ba600 authored by Dries's avatar Dries

Issue #2039199 by Berdir: Convert ->uid to ->id(), isAnonymous() and isAuthenticated().

parent 5feff937
......@@ -1550,7 +1550,7 @@ function watchdog($type, $message, array $variables = NULL, $severity = WATCHDOG
$in_error_state = TRUE;
// The user object may not exist in all conditions, so 0 is substituted if needed.
$user_uid = isset($user->uid) ? $user->uid : 0;
$user_uid = isset($user) ? $user->id() : 0;
// Prepare the fields to be logged
$log_entry = array(
......@@ -1898,7 +1898,7 @@ function drupal_get_user_timezone() {
global $user;
$config = config('system.timezone');
if ($user && $config->get('user.configurable') && $user->uid && $user->timezone) {
if ($user && $config->get('user.configurable') && $user->id() && $user->timezone) {
return $user->timezone;
}
else {
......
......@@ -3069,7 +3069,7 @@ function drupal_get_token($value = '') {
*/
function drupal_valid_token($token, $value = '', $skip_anonymous = FALSE) {
global $user;
return (($skip_anonymous && $user->uid == 0) || ($token == drupal_get_token($value)));
return (($skip_anonymous && $user->id() == 0) || ($token == drupal_get_token($value)));
}
/**
......@@ -4163,7 +4163,7 @@ function drupal_render_cid_parts($granularity = NULL) {
$cid_parts[] = 'r.' . implode(',', $user->roles);
}
elseif ($granularity & DRUPAL_CACHE_PER_USER) {
$cid_parts[] = "u.$user->uid";
$cid_parts[] = 'u.' . $user->id();
}
if ($granularity & DRUPAL_CACHE_PER_PAGE) {
......
......@@ -1123,7 +1123,7 @@ function file_save_upload($form_field_name, $validators = array(), $destination
}
// Begin building file entity.
$values = array(
'uid' => $user->uid,
'uid' => $user->id(),
'status' => 0,
'filename' => trim(drupal_basename($name, '.')),
'uri' => $uploaded_files['files']['tmp_name'][$form_field_name][$i],
......
......@@ -546,7 +546,7 @@ function drupal_rebuild_form($form_id, &$form_state, $old_form = NULL) {
function form_get_cache($form_build_id, &$form_state) {
if ($form = Drupal::keyValueExpirable('form')->get($form_build_id)) {
global $user;
if ((isset($form['#cache_token']) && drupal_valid_token($form['#cache_token'])) || (!isset($form['#cache_token']) && !$user->uid)) {
if ((isset($form['#cache_token']) && drupal_valid_token($form['#cache_token'])) || (!isset($form['#cache_token']) && $user->isAnonymous())) {
if ($stored_form_state = Drupal::keyValueExpirable('form_state')->get($form_build_id)) {
// Re-populate $form_state for subsequent rebuilds.
$form_state = $stored_form_state + $form_state;
......@@ -578,7 +578,7 @@ function form_set_cache($form_build_id, $form, $form_state) {
// Cache form structure.
if (isset($form)) {
if ($GLOBALS['user']->uid) {
if ($GLOBALS['user']->isAuthenticated()) {
$form['#cache_token'] = drupal_get_token();
}
Drupal::keyValueExpirable('form')->setWithExpire($form_build_id, $form, $expire);
......@@ -1069,7 +1069,7 @@ function drupal_prepare_form($form_id, &$form, &$form_state) {
// tokens are session-bound and forms displayed to anonymous users are very
// likely cached, we cannot assign a token for them.
// During installation, there is no $user yet.
if (!empty($user->uid) && !$form_state['programmed']) {
if ($user && $user->isAuthenticated() && !$form_state['programmed']) {
// Form constructors may explicitly set #token to FALSE when cross site
// request forgery is irrelevant to the form, such as search forms.
if (isset($form['#token']) && $form['#token'] === FALSE) {
......@@ -4888,7 +4888,7 @@ function _drupal_form_send_response(Response $response) {
* $batch = array(
* 'title' => t('Exporting'),
* 'operations' => array(
* array('my_function_1', array($account->uid, 'story')),
* array('my_function_1', array($account->id(), 'story')),
* array('my_function_2', array()),
* ),
* 'finished' => 'my_finished_callback',
......
......@@ -470,7 +470,7 @@ function language_negotiation_method_invoke($method_id, $method = NULL, $request
}
// If the language negotiation method has no cache preference or this is
// satisfied we can execute the callback.
$cache = !isset($method['cache']) || $user->uid || $method['cache'] == variable_get('cache', 0);
$cache = !isset($method['cache']) || $user->isAuthenticated() || $method['cache'] == variable_get('cache', 0);
$callback = isset($method['callbacks']['negotiation']) ? $method['callbacks']['negotiation'] : FALSE;
$langcode = $cache && function_exists($callback) ? $callback($languages, $request) : FALSE;
$results[$method_id] = isset($languages[$langcode]) ? $languages[$langcode] : FALSE;
......
......@@ -115,7 +115,7 @@ function _drupal_session_read($sid) {
if ($values && $values['uid'] > 0 && $values['status'] == 1) {
$user = new UserSession($values);
// Add roles element to $user.
$rids = db_query("SELECT ur.rid FROM {users_roles} ur WHERE ur.uid = :uid", array(':uid' => $user->uid))->fetchCol();
$rids = db_query("SELECT ur.rid FROM {users_roles} ur WHERE ur.uid = :uid", array(':uid' => $user->id()))->fetchCol();
$user->roles = array_merge(array(DRUPAL_AUTHENTICATED_RID), $rids);
}
elseif ($user) {
......@@ -180,7 +180,7 @@ function _drupal_session_write($sid, $value) {
if ($is_changed || !isset($user->timestamp) || REQUEST_TIME - $user->timestamp > settings()->get('session_write_interval', 180)) {
// Either ssid or sid or both will be added from $key below.
$fields = array(
'uid' => $user->uid,
'uid' => $user->id(),
'hostname' => Drupal::request()->getClientIP(),
'session' => $value,
'timestamp' => REQUEST_TIME,
......@@ -214,12 +214,12 @@ function _drupal_session_write($sid, $value) {
}
// Likewise, do not update access time more than once per 180 seconds.
if ($user->uid && REQUEST_TIME - $user->access > settings()->get('session_write_interval', 180)) {
if ($user->isAuthenticated() && REQUEST_TIME - $user->access > settings()->get('session_write_interval', 180)) {
db_update('users')
->fields(array(
'access' => REQUEST_TIME
))
->condition('uid', $user->uid)
->condition('uid', $user->id())
->execute();
}
......@@ -254,7 +254,7 @@ function drupal_session_initialize() {
// anonymous users not use a session cookie unless something is stored in
// $_SESSION. This allows HTTP proxies to cache anonymous pageviews.
drupal_session_start();
if (!empty($user->uid) || !empty($_SESSION)) {
if ($user->isAuthenticated() || !empty($_SESSION)) {
drupal_page_is_cacheable(FALSE);
}
}
......@@ -312,7 +312,7 @@ function drupal_session_commit() {
return;
}
if (empty($user->uid) && empty($_SESSION)) {
if ($user->isAnonymous() && empty($_SESSION)) {
// There is no session data to store, destroy the session if it was
// previously started.
if (drupal_session_started()) {
......
......@@ -2229,7 +2229,7 @@ function template_preprocess_tablesort_indicator(&$variables) {
function theme_mark($variables) {
$type = $variables['status'];
global $user;
if ($user->uid) {
if ($user->isAuthenticated()) {
if ($type == MARK_NEW) {
return ' <span class="marker">' . t('new') . '</span>';
}
......
......@@ -172,8 +172,8 @@ public function __unset($property_name) {
*/
public function access($operation = 'view', AccountInterface $account = NULL) {
global $user;
if (!isset($account) && $user->uid) {
$account = user_load($user->uid);
if (!isset($account)) {
$account = $user;
}
// Get the default access restriction that lives within this field.
$access = $this->defaultAccess($operation, $account);
......
......@@ -19,7 +19,7 @@ class UserSession implements AccountInterface {
*
* @var int
*/
public $uid;
protected $uid;
/**
* Session hostname.
......
......@@ -289,7 +289,7 @@ function _block_get_renderable_region($list = array()) {
// the regular 'roles define permissions' schema, it brings too many
// chances of having unwanted output get in the cache and later be served
// to other users. We therefore exclude user 1 from block caching.
$not_cacheable = $GLOBALS['user']->uid == 1 ||
$not_cacheable = $GLOBALS['user']->id() == 1 ||
count(module_implements('node_grants')) ||
!\Drupal::request()->isMethodSafe();
......
......@@ -49,7 +49,7 @@ function testBlockVisibility() {
$this->drupalGet('user');
$this->assertNoText($title, 'Block was not displayed according to block visibility rules.');
$this->drupalGet('USER/' . $this->adminUser->uid);
$this->drupalGet('USER/' . $this->adminUser->id());
$this->assertNoText($title, 'Block was not displayed according to block visibility rules regardless of path case.');
// Confirm that the block is not displayed to anonymous users.
......
......@@ -1252,7 +1252,7 @@ function comment_node_search_result(EntityInterface $node) {
function comment_user_cancel($edit, $account, $method) {
switch ($method) {
case 'user_cancel_block_unpublish':
$comments = entity_load_multiple_by_properties('comment', array('uid' => $account->uid));
$comments = entity_load_multiple_by_properties('comment', array('uid' => $account->id()));
foreach ($comments as $comment) {
$comment->status->value = 0;
$comment->save();
......@@ -1260,7 +1260,7 @@ function comment_user_cancel($edit, $account, $method) {
break;
case 'user_cancel_reassign':
$comments = entity_load_multiple_by_properties('comment', array('uid' => $account->uid));
$comments = entity_load_multiple_by_properties('comment', array('uid' => $account->id()));
foreach ($comments as $comment) {
$comment->uid->target_id = 0;
$comment->save();
......@@ -1273,7 +1273,7 @@ function comment_user_cancel($edit, $account, $method) {
* Implements hook_user_predelete().
*/
function comment_user_predelete($account) {
$cids = db_query('SELECT c.cid FROM {comment} c WHERE uid = :uid', array(':uid' => $account->uid))->fetchCol();
$cids = db_query('SELECT c.cid FROM {comment} c WHERE uid = :uid', array(':uid' => $account->id()))->fetchCol();
entity_delete_multiple('comment', $cids);
}
......@@ -1325,7 +1325,7 @@ function comment_load($cid, $reset = FALSE) {
function comment_num_new($nid, $timestamp = 0) {
global $user;
if ($user->uid && module_exists('history')) {
if ($user->isAuthenticated() && module_exists('history')) {
// Retrieve the timestamp at which the current user last viewed this node.
if (!$timestamp) {
$timestamp = history_read($nid);
......@@ -1423,12 +1423,12 @@ function comment_preview(Comment $comment) {
if (!empty($comment->name->value)) {
$account = user_load_by_name($comment->name->value);
}
elseif ($user->uid && empty($comment->is_anonymous)) {
elseif ($user->isAuthenticated() && empty($comment->is_anonymous)) {
$account = $user;
}
if (!empty($account->uid)) {
$comment->uid->target_id = $account->uid;
if ($account->id()) {
$comment->uid->target_id = $account->id();
$comment->name->value = check_plain($account->name);
}
elseif (empty($comment->name->value)) {
......@@ -1613,7 +1613,7 @@ function template_preprocess_comment(&$variables) {
if ($comment->uid->target_id == $variables['node']->uid) {
$variables['attributes']['class'][] = 'by-node-author';
}
if ($comment->uid->target_id == $variables['user']->uid) {
if ($comment->uid->target_id == $variables['user']->id()) {
$variables['attributes']['class'][] = 'by-viewer';
}
}
......@@ -1640,7 +1640,7 @@ function theme_comment_post_forbidden($variables) {
// comments only has to query the database once for all the links.
$authenticated_post_comments = &drupal_static(__FUNCTION__, NULL);
if (!$user->uid) {
if ($user->isAnonymous()) {
if (!isset($authenticated_post_comments)) {
// We only output a link if we are certain that users will get permission
// to post comments by logging in.
......
......@@ -32,7 +32,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A
break;
case 'update':
return ($account->uid && $account->uid == $entity->uid->value && $entity->status->value == COMMENT_PUBLISHED && user_access('edit own comments', $account)) || user_access('administer comments', $account);
return ($account->id() && $account->id() == $entity->uid->value && $entity->status->value == COMMENT_PUBLISHED && user_access('edit own comments', $account)) || user_access('administer comments', $account);
break;
case 'delete':
......
......@@ -31,7 +31,7 @@ public function form(array $form, array &$form_state) {
$anonymous_contact = variable_get('comment_anonymous_' . $node->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT);
$is_admin = $comment->id() && user_access('administer comments');
if (!$user->uid && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT) {
if (!$user->isAuthenticated() && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT) {
$form['#attached']['library'][] = array('system', 'jquery.cookie');
$form['#attributes']['class'][] = 'user-info-from-cookie';
}
......@@ -65,7 +65,7 @@ public function form(array $form, array &$form_state) {
$date = (!empty($comment->date) ? $comment->date : new DrupalDateTime($comment->created->value));
}
else {
if ($user->uid) {
if ($user->isAuthenticated()) {
$author = $user->name;
}
else {
......@@ -80,7 +80,7 @@ public function form(array $form, array &$form_state) {
'#type' => 'textfield',
'#title' => t('Your name'),
'#default_value' => $author,
'#required' => (!$user->uid && $anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT),
'#required' => ($user->isAnonymous() && $anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT),
'#maxlength' => 60,
'#size' => 30,
);
......@@ -89,7 +89,7 @@ public function form(array $form, array &$form_state) {
$form['author']['name']['#description'] = t('Leave blank for %anonymous.', array('%anonymous' => config('user.settings')->get('anonymous')));
$form['author']['name']['#autocomplete_path'] = 'user/autocomplete';
}
elseif ($user->uid) {
elseif ($user->isAuthenticated()) {
$form['author']['name']['#type'] = 'item';
$form['author']['name']['#value'] = $form['author']['name']['#default_value'];
$username = array(
......@@ -104,11 +104,11 @@ public function form(array $form, array &$form_state) {
'#type' => 'email',
'#title' => t('E-mail'),
'#default_value' => $comment->mail->value,
'#required' => (!$user->uid && $anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT),
'#required' => ($user->isAnonymous() && $anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT),
'#maxlength' => 64,
'#size' => 30,
'#description' => t('The content of this field is kept private and will not be shown publicly.'),
'#access' => $is_admin || (!$user->uid && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT),
'#access' => $is_admin || ($user->isAnonymous() && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT),
);
$form['author']['homepage'] = array(
......@@ -117,7 +117,7 @@ public function form(array $form, array &$form_state) {
'#default_value' => $comment->homepage->value,
'#maxlength' => 255,
'#size' => 30,
'#access' => $is_admin || (!$user->uid && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT),
'#access' => $is_admin || ($user->isAnonymous() && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT),
);
// Add administrative comment publishing options.
......@@ -151,7 +151,7 @@ public function form(array $form, array &$form_state) {
// Used for conditional validation of author fields.
$form['is_anonymous'] = array(
'#type' => 'value',
'#value' => ($comment->id() ? !$comment->uid->target_id : !$user->uid),
'#value' => ($comment->id() ? !$comment->uid->target_id : $user->isAnonymous()),
);
// Make the comment inherit the current content language unless specifically
......@@ -215,7 +215,7 @@ public function validate(array $form, array &$form_state) {
if (!empty($form_state['values']['cid'])) {
// Verify the name in case it is being changed from being anonymous.
$account = user_load_by_name($form_state['values']['name']);
$form_state['values']['uid'] = $account ? $account->uid : 0;
$form_state['values']['uid'] = $account ? $account->id() : 0;
$date = $form_state['values']['date'];
if ($date instanceOf DrupalDateTime && $date->hasErrors()) {
......@@ -269,7 +269,7 @@ public function submit(array $form, array &$form_state) {
// @todo Too fragile. Should be prepared and stored in comment_form()
// already.
if (!$comment->is_anonymous && !empty($comment->name->value) && ($account = user_load_by_name($comment->name->value))) {
$comment->uid->target_id = $account->uid;
$comment->uid->target_id = $account->id();
}
// If the comment was posted by an anonymous user and no author name was
// required, use "Anonymous" by default.
......
......@@ -301,7 +301,7 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
}
// We test the value with '===' because we need to modify anonymous
// users as well.
if ($this->uid->target_id === $user->uid && $user->uid) {
if ($this->uid->target_id === $user->id() && $user->isAuthenticated()) {
$this->name->value = $user->name;
}
// Add the values which aren't passed into the function.
......
......@@ -93,7 +93,7 @@ public function query() {
public function preRender(&$values) {
global $user;
if (!$user->uid || empty($values)) {
if ($user->isAnonymous() || empty($values)) {
return;
}
......@@ -114,7 +114,7 @@ public function preRender(&$values) {
LEFT JOIN {history} h ON h.nid = n.nid AND h.uid = :h_uid WHERE n.nid IN (:nids)
AND c.changed > GREATEST(COALESCE(h.timestamp, :timestamp), :timestamp) AND c.status = :status GROUP BY n.nid', array(
':status' => COMMENT_PUBLISHED,
':h_uid' => $user->uid,
':h_uid' => $user->id(),
':nids' => $nids,
':timestamp' => HISTORY_READ_LIMIT,
));
......
......@@ -38,8 +38,8 @@ function setUp() {
function testCommentClasses() {
// Create all permutations for comments, users, and nodes.
$parameters = array(
'node_uid' => array(0, $this->web_user->uid),
'comment_uid' => array(0, $this->web_user->uid, $this->admin_user->uid),
'node_uid' => array(0, $this->web_user->id()),
'comment_uid' => array(0, $this->web_user->id(), $this->admin_user->id()),
'comment_status' => array(COMMENT_PUBLISHED, COMMENT_NOT_PUBLISHED),
'user' => array('anonymous', 'authenticated', 'admin'),
);
......@@ -72,12 +72,12 @@ function testCommentClasses() {
case 'authenticated':
$this->drupalLogin($this->web_user);
$case['user_uid'] = $this->web_user->uid;
$case['user_uid'] = $this->web_user->id();
break;
case 'admin':
$this->drupalLogin($this->admin_user);
$case['user_uid'] = $this->admin_user->uid;
$case['user_uid'] = $this->admin_user->id();
break;
}
// Request the node with the comment.
......
......@@ -81,7 +81,7 @@ function testCommentInterface() {
// Test changing the comment author to a verified user.
$this->drupalGet('comment/' . $comment->id() . '/edit');
$comment = $this->postComment(NULL, $comment->comment_body->value, $comment->subject->value, array('name' => $this->web_user->name));
$this->assertTrue($comment->name->value == $this->web_user->name && $comment->uid->target_id == $this->web_user->uid, 'Comment author successfully changed to a registered user.');
$this->assertTrue($comment->name->value == $this->web_user->name && $comment->uid->target_id == $this->web_user->id(), 'Comment author successfully changed to a registered user.');
$this->drupalLogout();
......
......@@ -68,7 +68,7 @@ function setUp() {
// Change user language preference, this way interface language is always
// French no matter what path prefix the URLs have.
$edit = array('preferred_langcode' => 'fr');
$this->drupalPost("user/{$admin_user->uid}/edit", $edit, t('Save'));
$this->drupalPost("user/" . $admin_user->id() . "/edit", $edit, t('Save'));
// Make comment body translatable.
$field = field_info_field('comment_body');
......
......@@ -51,7 +51,7 @@ public function testCommentNewCommentsIndicator() {
'nid' => $this->node->nid,
'node_type' => $this->node->type,
'pid' => 0,
'uid' => $this->loggedInUser->uid,
'uid' => $this->loggedInUser->id(),
'status' => COMMENT_PUBLISHED,
'subject' => $this->randomName(),
'hostname' => '127.0.0.1',
......
......@@ -52,7 +52,7 @@ function testCommentPreview() {
$edit['signature[value]'] = '<a href="http://example.com/">' . $test_signature. '</a>';
$image = current($this->drupalGetTestFiles('image'));
$edit['files[user_picture_und_0]'] = drupal_realpath($image->uri);
$this->drupalPost('user/' . $this->web_user->uid . '/edit', $edit, t('Save'));
$this->drupalPost('user/' . $this->web_user->id() . '/edit', $edit, t('Save'));
// As the web user, fill in the comment form and preview the comment.
$edit = array();
......
......@@ -51,7 +51,7 @@ function testCommentNodeCommentStatistics() {
$node = node_load($this->node->nid);
$this->assertEqual($node->last_comment_timestamp, $this->node->created, 'The initial value of node last_comment_timestamp is the node created date.');
$this->assertEqual($node->last_comment_name, NULL, 'The initial value of node last_comment_name is NULL.');
$this->assertEqual($node->last_comment_uid, $this->web_user->uid, 'The initial value of node last_comment_uid is the node uid.');
$this->assertEqual($node->last_comment_uid, $this->web_user->id(), 'The initial value of node last_comment_uid is the node uid.');
$this->assertEqual($node->comment_count, 0, 'The initial value of node comment_count is zero.');
// Post comment #1 as web_user2.
......@@ -63,7 +63,7 @@ function testCommentNodeCommentStatistics() {
// The node needs to be reloaded with a node_load_multiple cache reset.
$node = node_load($this->node->nid, TRUE);
$this->assertEqual($node->last_comment_name, NULL, 'The value of node last_comment_name is NULL.');
$this->assertEqual($node->last_comment_uid, $this->web_user2->uid, 'The value of node last_comment_uid is the comment #1 uid.');
$this->assertEqual($node->last_comment_uid, $this->web_user2->id(), 'The value of node last_comment_uid is the comment #1 uid.');
$this->assertEqual($node->comment_count, 1, 'The value of node comment_count is 1.');
// Prepare for anonymous comment submission (comment approval enabled).
......@@ -86,7 +86,7 @@ function testCommentNodeCommentStatistics() {
// The node needs to be reloaded with a node_load_multiple cache reset.
$node = node_load($this->node->nid, TRUE);
$this->assertEqual($node->last_comment_name, NULL, 'The value of node last_comment_name is still NULL.');
$this->assertEqual($node->last_comment_uid, $this->web_user2->uid, 'The value of node last_comment_uid is still the comment #1 uid.');
$this->assertEqual($node->last_comment_uid, $this->web_user2->id(), 'The value of node last_comment_uid is still the comment #1 uid.');
$this->assertEqual($node->comment_count, 1, 'The value of node comment_count is still 1.');
// Prepare for anonymous comment submission (no approval required).
......
......@@ -75,7 +75,7 @@ function setUp() {
));
// Create a test node authored by the web user.
$this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->web_user->uid));
$this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->web_user->id()));
}
/**
......
......@@ -36,7 +36,7 @@ function testCommentThreading() {
// Create a node.
$this->drupalLogin($this->web_user);
$this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->web_user->uid));
$this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->web_user->id()));
// Post comment #1.
$this->drupalLogin($this->web_user);
......
......@@ -29,7 +29,7 @@ public static function getInfo() {
function testCommentUserUIDTest() {
$view = views_get_view('test_comment_user_uid');
$this->executeView($view, array($this->account->uid));
$this->executeView($view, array($this->account->id()));
$result_set = array(
array(
'nid' => $this->node_user_posted->nid,
......
......@@ -44,7 +44,7 @@ function setUp() {
$this->node_user_commented = $this->drupalCreateNode(array('uid' => $this->account2->uid));
$comment = array(
'uid' => $this->loggedInUser->uid,
'uid' => $this->loggedInUser->id(),
'nid' => $this->node_user_commented->nid,
'cid' => '',
'pid' => '',
......
......@@ -38,10 +38,10 @@ function testCommentUserUIDTest() {
'id' => 'uid_touch',
'table' => 'node_field_data',
'field' => 'uid_touch',
'value' => array($this->loggedInUser->uid),
'value' => array($this->loggedInUser->id()),
);
$view->addItem('default', 'filter', 'node_field_data', 'uid_touch', $options);
$this->executeView($view, array($this->account->uid));
$this->executeView($view, array($this->account->id()));
$result_set = array(
array(
'nid' => $this->node_user_posted->nid,
......
......@@ -126,12 +126,12 @@ function _contact_personal_tab_access($account) {
global $user;
// Anonymous users cannot have contact forms.
if (!$account->uid) {
if ($account->isAnonymous()) {
return FALSE;
}
// Users may not contact themselves.
if ($user->uid == $account->uid) {
if ($user->id() == $account->id()) {
return FALSE;
}
......@@ -269,7 +269,7 @@ function contact_mail($key, &$message, $params) {
'!form-url' => url(current_path(), array('absolute' => TRUE, 'language' => $language)),
'!sender-name' => user_format_name($sender),
);
if (!empty($sender->uid)) {
if ($sender->isAuthenticated()) {
$sender_uri = $sender->uri();
$variables['!sender-url'] = url($sender_uri['path'], array('absolute' => TRUE, 'language' => $language) + $sender_uri['options']);
}
......@@ -297,7 +297,7 @@ function contact_mail($key, &$message, $params) {
case 'user_copy':
$variables += array(
'!recipient-name' => user_format_name($params['recipient']),
'!recipient-edit-url' => url('user/' . $params['recipient']->uid . '/edit', array('absolute' => TRUE, 'language' => $language)),
'!recipient-edit-url' => url('user/' . $params['recipient']->id() . '/edit', array('absolute' => TRUE, 'language' => $language)),
);
$message['subject'] .= t('[!site-name] !subject', $variables, $options);
$message['body'][] = t('Hello !recipient-name,', $variables, $options);
......
......@@ -44,7 +44,7 @@ public function form(array $form, array &$form_state) {
'#title' => t('Your e-mail address'),
'#required' => TRUE,
);
if (!$user->uid) {
if ($user->isAnonymous()) {
$form['#attached']['library'][] = array('system', 'jquery.cookie');
$form['#attributes']['class'][] = 'user-info-from-cookie';
}
......@@ -93,7 +93,7 @@ public function form(array $form, array &$form_state) {
'#title' => t('Send yourself a copy.'),
// Do not allow anonymous users to send themselves a copy, because it can
// be abused to spam people.
'#access' => !empty($user->uid),
'#access' => $user->isAuthenticated(),
);
return $form;
}
......@@ -136,8 +136,8 @@ public function save(array $form, array &$form_state) {
$language_interface = language(Language::TYPE_INTERFACE);
$message = $this->entity;
$sender = clone user_load($user->uid);
if (!$user->uid) {
$sender = clone user_load($user->id());
if ($user->isAnonymous()) {
// At this point, $sender contains drupal_anonymous_user(), so we need to
// take over the submitted form values.
$sender->name = $message->getSenderName();
......
......@@ -92,22 +92,22 @@ function testSendPersonalContactMessage() {
function testPersonalContactAccess() {
// Test allowed access to admin user's contact form.
$this->drupalLogin($this->web_user);
$this->drupalGet('user/' . $this->admin_user->uid . '/contact');
$this->drupalGet('user/' . $this->admin_user->id() . '/contact');
$this->assertResponse(200);
// Test denied access to admin user's own contact form.
$this->drupalLogout();
$this->drupalLogin($this->admin_user);
$this->drupalGet('user/' . $this->admin_user->uid . '/contact');
$this->drupalGet('user/' . $this->admin_user->id() . '/contact');
$this->assertResponse(403);