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 ...@@ -1550,7 +1550,7 @@ function watchdog($type, $message, array $variables = NULL, $severity = WATCHDOG
$in_error_state = TRUE; $in_error_state = TRUE;
// The user object may not exist in all conditions, so 0 is substituted if needed. // 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 // Prepare the fields to be logged
$log_entry = array( $log_entry = array(
...@@ -1898,7 +1898,7 @@ function drupal_get_user_timezone() { ...@@ -1898,7 +1898,7 @@ function drupal_get_user_timezone() {
global $user; global $user;
$config = config('system.timezone'); $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; return $user->timezone;
} }
else { else {
......
...@@ -3069,7 +3069,7 @@ function drupal_get_token($value = '') { ...@@ -3069,7 +3069,7 @@ function drupal_get_token($value = '') {
*/ */
function drupal_valid_token($token, $value = '', $skip_anonymous = FALSE) { function drupal_valid_token($token, $value = '', $skip_anonymous = FALSE) {
global $user; 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) { ...@@ -4163,7 +4163,7 @@ function drupal_render_cid_parts($granularity = NULL) {
$cid_parts[] = 'r.' . implode(',', $user->roles); $cid_parts[] = 'r.' . implode(',', $user->roles);
} }
elseif ($granularity & DRUPAL_CACHE_PER_USER) { elseif ($granularity & DRUPAL_CACHE_PER_USER) {
$cid_parts[] = "u.$user->uid"; $cid_parts[] = 'u.' . $user->id();
} }
if ($granularity & DRUPAL_CACHE_PER_PAGE) { if ($granularity & DRUPAL_CACHE_PER_PAGE) {
......
...@@ -1123,7 +1123,7 @@ function file_save_upload($form_field_name, $validators = array(), $destination ...@@ -1123,7 +1123,7 @@ function file_save_upload($form_field_name, $validators = array(), $destination
} }
// Begin building file entity. // Begin building file entity.
$values = array( $values = array(
'uid' => $user->uid, 'uid' => $user->id(),
'status' => 0, 'status' => 0,
'filename' => trim(drupal_basename($name, '.')), 'filename' => trim(drupal_basename($name, '.')),
'uri' => $uploaded_files['files']['tmp_name'][$form_field_name][$i], '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) { ...@@ -546,7 +546,7 @@ function drupal_rebuild_form($form_id, &$form_state, $old_form = NULL) {
function form_get_cache($form_build_id, &$form_state) { function form_get_cache($form_build_id, &$form_state) {
if ($form = Drupal::keyValueExpirable('form')->get($form_build_id)) { if ($form = Drupal::keyValueExpirable('form')->get($form_build_id)) {
global $user; 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)) { if ($stored_form_state = Drupal::keyValueExpirable('form_state')->get($form_build_id)) {
// Re-populate $form_state for subsequent rebuilds. // Re-populate $form_state for subsequent rebuilds.
$form_state = $stored_form_state + $form_state; $form_state = $stored_form_state + $form_state;
...@@ -578,7 +578,7 @@ function form_set_cache($form_build_id, $form, $form_state) { ...@@ -578,7 +578,7 @@ function form_set_cache($form_build_id, $form, $form_state) {
// Cache form structure. // Cache form structure.
if (isset($form)) { if (isset($form)) {
if ($GLOBALS['user']->uid) { if ($GLOBALS['user']->isAuthenticated()) {
$form['#cache_token'] = drupal_get_token(); $form['#cache_token'] = drupal_get_token();
} }
Drupal::keyValueExpirable('form')->setWithExpire($form_build_id, $form, $expire); Drupal::keyValueExpirable('form')->setWithExpire($form_build_id, $form, $expire);
...@@ -1069,7 +1069,7 @@ function drupal_prepare_form($form_id, &$form, &$form_state) { ...@@ -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 // tokens are session-bound and forms displayed to anonymous users are very
// likely cached, we cannot assign a token for them. // likely cached, we cannot assign a token for them.
// During installation, there is no $user yet. // 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 // Form constructors may explicitly set #token to FALSE when cross site
// request forgery is irrelevant to the form, such as search forms. // request forgery is irrelevant to the form, such as search forms.
if (isset($form['#token']) && $form['#token'] === FALSE) { if (isset($form['#token']) && $form['#token'] === FALSE) {
...@@ -4888,7 +4888,7 @@ function _drupal_form_send_response(Response $response) { ...@@ -4888,7 +4888,7 @@ function _drupal_form_send_response(Response $response) {
* $batch = array( * $batch = array(
* 'title' => t('Exporting'), * 'title' => t('Exporting'),
* 'operations' => array( * 'operations' => array(
* array('my_function_1', array($account->uid, 'story')), * array('my_function_1', array($account->id(), 'story')),
* array('my_function_2', array()), * array('my_function_2', array()),
* ), * ),
* 'finished' => 'my_finished_callback', * 'finished' => 'my_finished_callback',
......
...@@ -470,7 +470,7 @@ function language_negotiation_method_invoke($method_id, $method = NULL, $request ...@@ -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 // If the language negotiation method has no cache preference or this is
// satisfied we can execute the callback. // 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; $callback = isset($method['callbacks']['negotiation']) ? $method['callbacks']['negotiation'] : FALSE;
$langcode = $cache && function_exists($callback) ? $callback($languages, $request) : FALSE; $langcode = $cache && function_exists($callback) ? $callback($languages, $request) : FALSE;
$results[$method_id] = isset($languages[$langcode]) ? $languages[$langcode] : FALSE; $results[$method_id] = isset($languages[$langcode]) ? $languages[$langcode] : FALSE;
......
...@@ -115,7 +115,7 @@ function _drupal_session_read($sid) { ...@@ -115,7 +115,7 @@ function _drupal_session_read($sid) {
if ($values && $values['uid'] > 0 && $values['status'] == 1) { if ($values && $values['uid'] > 0 && $values['status'] == 1) {
$user = new UserSession($values); $user = new UserSession($values);
// Add roles element to $user. // 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); $user->roles = array_merge(array(DRUPAL_AUTHENTICATED_RID), $rids);
} }
elseif ($user) { elseif ($user) {
...@@ -180,7 +180,7 @@ function _drupal_session_write($sid, $value) { ...@@ -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)) { 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. // Either ssid or sid or both will be added from $key below.
$fields = array( $fields = array(
'uid' => $user->uid, 'uid' => $user->id(),
'hostname' => Drupal::request()->getClientIP(), 'hostname' => Drupal::request()->getClientIP(),
'session' => $value, 'session' => $value,
'timestamp' => REQUEST_TIME, 'timestamp' => REQUEST_TIME,
...@@ -214,12 +214,12 @@ function _drupal_session_write($sid, $value) { ...@@ -214,12 +214,12 @@ function _drupal_session_write($sid, $value) {
} }
// Likewise, do not update access time more than once per 180 seconds. // 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') db_update('users')
->fields(array( ->fields(array(
'access' => REQUEST_TIME 'access' => REQUEST_TIME
)) ))
->condition('uid', $user->uid) ->condition('uid', $user->id())
->execute(); ->execute();
} }
...@@ -254,7 +254,7 @@ function drupal_session_initialize() { ...@@ -254,7 +254,7 @@ function drupal_session_initialize() {
// anonymous users not use a session cookie unless something is stored in // anonymous users not use a session cookie unless something is stored in
// $_SESSION. This allows HTTP proxies to cache anonymous pageviews. // $_SESSION. This allows HTTP proxies to cache anonymous pageviews.
drupal_session_start(); drupal_session_start();
if (!empty($user->uid) || !empty($_SESSION)) { if ($user->isAuthenticated() || !empty($_SESSION)) {
drupal_page_is_cacheable(FALSE); drupal_page_is_cacheable(FALSE);
} }
} }
...@@ -312,7 +312,7 @@ function drupal_session_commit() { ...@@ -312,7 +312,7 @@ function drupal_session_commit() {
return; 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 // There is no session data to store, destroy the session if it was
// previously started. // previously started.
if (drupal_session_started()) { if (drupal_session_started()) {
......
...@@ -2229,7 +2229,7 @@ function template_preprocess_tablesort_indicator(&$variables) { ...@@ -2229,7 +2229,7 @@ function template_preprocess_tablesort_indicator(&$variables) {
function theme_mark($variables) { function theme_mark($variables) {
$type = $variables['status']; $type = $variables['status'];
global $user; global $user;
if ($user->uid) { if ($user->isAuthenticated()) {
if ($type == MARK_NEW) { if ($type == MARK_NEW) {
return ' <span class="marker">' . t('new') . '</span>'; return ' <span class="marker">' . t('new') . '</span>';
} }
......
...@@ -172,8 +172,8 @@ public function __unset($property_name) { ...@@ -172,8 +172,8 @@ public function __unset($property_name) {
*/ */
public function access($operation = 'view', AccountInterface $account = NULL) { public function access($operation = 'view', AccountInterface $account = NULL) {
global $user; global $user;
if (!isset($account) && $user->uid) { if (!isset($account)) {
$account = user_load($user->uid); $account = $user;
} }
// Get the default access restriction that lives within this field. // Get the default access restriction that lives within this field.
$access = $this->defaultAccess($operation, $account); $access = $this->defaultAccess($operation, $account);
......
...@@ -19,7 +19,7 @@ class UserSession implements AccountInterface { ...@@ -19,7 +19,7 @@ class UserSession implements AccountInterface {
* *
* @var int * @var int
*/ */
public $uid; protected $uid;
/** /**
* Session hostname. * Session hostname.
......
...@@ -289,7 +289,7 @@ function _block_get_renderable_region($list = array()) { ...@@ -289,7 +289,7 @@ function _block_get_renderable_region($list = array()) {
// the regular 'roles define permissions' schema, it brings too many // the regular 'roles define permissions' schema, it brings too many
// chances of having unwanted output get in the cache and later be served // chances of having unwanted output get in the cache and later be served
// to other users. We therefore exclude user 1 from block caching. // 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')) || count(module_implements('node_grants')) ||
!\Drupal::request()->isMethodSafe(); !\Drupal::request()->isMethodSafe();
......
...@@ -49,7 +49,7 @@ function testBlockVisibility() { ...@@ -49,7 +49,7 @@ function testBlockVisibility() {
$this->drupalGet('user'); $this->drupalGet('user');
$this->assertNoText($title, 'Block was not displayed according to block visibility rules.'); $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.'); $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. // Confirm that the block is not displayed to anonymous users.
......
...@@ -1252,7 +1252,7 @@ function comment_node_search_result(EntityInterface $node) { ...@@ -1252,7 +1252,7 @@ function comment_node_search_result(EntityInterface $node) {
function comment_user_cancel($edit, $account, $method) { function comment_user_cancel($edit, $account, $method) {
switch ($method) { switch ($method) {
case 'user_cancel_block_unpublish': 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) { foreach ($comments as $comment) {
$comment->status->value = 0; $comment->status->value = 0;
$comment->save(); $comment->save();
...@@ -1260,7 +1260,7 @@ function comment_user_cancel($edit, $account, $method) { ...@@ -1260,7 +1260,7 @@ function comment_user_cancel($edit, $account, $method) {
break; break;
case 'user_cancel_reassign': 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) { foreach ($comments as $comment) {
$comment->uid->target_id = 0; $comment->uid->target_id = 0;
$comment->save(); $comment->save();
...@@ -1273,7 +1273,7 @@ function comment_user_cancel($edit, $account, $method) { ...@@ -1273,7 +1273,7 @@ function comment_user_cancel($edit, $account, $method) {
* Implements hook_user_predelete(). * Implements hook_user_predelete().
*/ */
function comment_user_predelete($account) { 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); entity_delete_multiple('comment', $cids);
} }
...@@ -1325,7 +1325,7 @@ function comment_load($cid, $reset = FALSE) { ...@@ -1325,7 +1325,7 @@ function comment_load($cid, $reset = FALSE) {
function comment_num_new($nid, $timestamp = 0) { function comment_num_new($nid, $timestamp = 0) {
global $user; 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. // Retrieve the timestamp at which the current user last viewed this node.
if (!$timestamp) { if (!$timestamp) {
$timestamp = history_read($nid); $timestamp = history_read($nid);
...@@ -1423,12 +1423,12 @@ function comment_preview(Comment $comment) { ...@@ -1423,12 +1423,12 @@ function comment_preview(Comment $comment) {
if (!empty($comment->name->value)) { if (!empty($comment->name->value)) {
$account = user_load_by_name($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; $account = $user;
} }
if (!empty($account->uid)) { if ($account->id()) {
$comment->uid->target_id = $account->uid; $comment->uid->target_id = $account->id();
$comment->name->value = check_plain($account->name); $comment->name->value = check_plain($account->name);
} }
elseif (empty($comment->name->value)) { elseif (empty($comment->name->value)) {
...@@ -1613,7 +1613,7 @@ function template_preprocess_comment(&$variables) { ...@@ -1613,7 +1613,7 @@ function template_preprocess_comment(&$variables) {
if ($comment->uid->target_id == $variables['node']->uid) { if ($comment->uid->target_id == $variables['node']->uid) {
$variables['attributes']['class'][] = 'by-node-author'; $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'; $variables['attributes']['class'][] = 'by-viewer';
} }
} }
...@@ -1640,7 +1640,7 @@ function theme_comment_post_forbidden($variables) { ...@@ -1640,7 +1640,7 @@ function theme_comment_post_forbidden($variables) {
// comments only has to query the database once for all the links. // comments only has to query the database once for all the links.
$authenticated_post_comments = &drupal_static(__FUNCTION__, NULL); $authenticated_post_comments = &drupal_static(__FUNCTION__, NULL);
if (!$user->uid) { if ($user->isAnonymous()) {
if (!isset($authenticated_post_comments)) { if (!isset($authenticated_post_comments)) {
// We only output a link if we are certain that users will get permission // We only output a link if we are certain that users will get permission
// to post comments by logging in. // to post comments by logging in.
......
...@@ -32,7 +32,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A ...@@ -32,7 +32,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A
break; break;
case 'update': 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; break;
case 'delete': case 'delete':
......
...@@ -31,7 +31,7 @@ public function form(array $form, array &$form_state) { ...@@ -31,7 +31,7 @@ public function form(array $form, array &$form_state) {
$anonymous_contact = variable_get('comment_anonymous_' . $node->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT); $anonymous_contact = variable_get('comment_anonymous_' . $node->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT);
$is_admin = $comment->id() && user_access('administer comments'); $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['#attached']['library'][] = array('system', 'jquery.cookie');
$form['#attributes']['class'][] = 'user-info-from-cookie'; $form['#attributes']['class'][] = 'user-info-from-cookie';
} }
...@@ -65,7 +65,7 @@ public function form(array $form, array &$form_state) { ...@@ -65,7 +65,7 @@ public function form(array $form, array &$form_state) {
$date = (!empty($comment->date) ? $comment->date : new DrupalDateTime($comment->created->value)); $date = (!empty($comment->date) ? $comment->date : new DrupalDateTime($comment->created->value));
} }
else { else {
if ($user->uid) { if ($user->isAuthenticated()) {
$author = $user->name; $author = $user->name;
} }
else { else {
...@@ -80,7 +80,7 @@ public function form(array $form, array &$form_state) { ...@@ -80,7 +80,7 @@ public function form(array $form, array &$form_state) {
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Your name'), '#title' => t('Your name'),
'#default_value' => $author, '#default_value' => $author,
'#required' => (!$user->uid && $anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT), '#required' => ($user->isAnonymous() && $anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT),
'#maxlength' => 60, '#maxlength' => 60,
'#size' => 30, '#size' => 30,
); );
...@@ -89,7 +89,7 @@ public function form(array $form, array &$form_state) { ...@@ -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']['#description'] = t('Leave blank for %anonymous.', array('%anonymous' => config('user.settings')->get('anonymous')));
$form['author']['name']['#autocomplete_path'] = 'user/autocomplete'; $form['author']['name']['#autocomplete_path'] = 'user/autocomplete';
} }
elseif ($user->uid) { elseif ($user->isAuthenticated()) {
$form['author']['name']['#type'] = 'item'; $form['author']['name']['#type'] = 'item';
$form['author']['name']['#value'] = $form['author']['name']['#default_value']; $form['author']['name']['#value'] = $form['author']['name']['#default_value'];
$username = array( $username = array(
...@@ -104,11 +104,11 @@ public function form(array $form, array &$form_state) { ...@@ -104,11 +104,11 @@ public function form(array $form, array &$form_state) {
'#type' => 'email', '#type' => 'email',
'#title' => t('E-mail'), '#title' => t('E-mail'),
'#default_value' => $comment->mail->value, '#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, '#maxlength' => 64,
'#size' => 30, '#size' => 30,
'#description' => t('The content of this field is kept private and will not be shown publicly.'), '#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( $form['author']['homepage'] = array(
...@@ -117,7 +117,7 @@ public function form(array $form, array &$form_state) { ...@@ -117,7 +117,7 @@ public function form(array $form, array &$form_state) {
'#default_value' => $comment->homepage->value, '#default_value' => $comment->homepage->value,
'#maxlength' => 255, '#maxlength' => 255,
'#size' => 30, '#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. // Add administrative comment publishing options.
...@@ -151,7 +151,7 @@ public function form(array $form, array &$form_state) { ...@@ -151,7 +151,7 @@ public function form(array $form, array &$form_state) {
// Used for conditional validation of author fields. // Used for conditional validation of author fields.
$form['is_anonymous'] = array( $form['is_anonymous'] = array(
'#type' => 'value', '#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 // Make the comment inherit the current content language unless specifically
...@@ -215,7 +215,7 @@ public function validate(array $form, array &$form_state) { ...@@ -215,7 +215,7 @@ public function validate(array $form, array &$form_state) {
if (!empty($form_state['values']['cid'])) { if (!empty($form_state['values']['cid'])) {
// Verify the name in case it is being changed from being anonymous. // Verify the name in case it is being changed from being anonymous.
$account = user_load_by_name($form_state['values']['name']); $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']; $date = $form_state['values']['date'];
if ($date instanceOf DrupalDateTime && $date->hasErrors()) { if ($date instanceOf DrupalDateTime && $date->hasErrors()) {
...@@ -269,7 +269,7 @@ public function submit(array $form, array &$form_state) { ...@@ -269,7 +269,7 @@ public function submit(array $form, array &$form_state) {
// @todo Too fragile. Should be prepared and stored in comment_form() // @todo Too fragile. Should be prepared and stored in comment_form()
// already. // already.
if (!$comment->is_anonymous && !empty($comment->name->value) && ($account = user_load_by_name($comment->name->value))) { 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 // If the comment was posted by an anonymous user and no author name was
// required, use "Anonymous" by default. // required, use "Anonymous" by default.
......
...@@ -301,7 +301,7 @@ public function preSave(EntityStorageControllerInterface $storage_controller) { ...@@ -301,7 +301,7 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
} }
// We test the value with '===' because we need to modify anonymous // We test the value with '===' because we need to modify anonymous
// users as well. // 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; $this->name->value = $user->name;
} }
// Add the values which aren't passed into the function. // Add the values which aren't passed into the function.
......
...@@ -93,7 +93,7 @@ public function query() { ...@@ -93,7 +93,7 @@ public function query() {
public function preRender(&$values) { public function preRender(&$values) {
global $user; global $user;
if (!$user->uid || empty($values)) { if ($user->isAnonymous() || empty($values)) {
return; return;
} }
...@@ -114,7 +114,7 @@ public function preRender(&$values) { ...@@ -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) 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( AND c.changed > GREATEST(COALESCE(h.timestamp, :timestamp), :timestamp) AND c.status = :status GROUP BY n.nid', array(
':status' => COMMENT_PUBLISHED, ':status' => COMMENT_PUBLISHED,
':h_uid' => $user->uid, ':h_uid' => $user->id(),
':nids' => $nids, ':nids' => $nids,
':timestamp' => HISTORY_READ_LIMIT, ':timestamp' => HISTORY_READ_LIMIT,
)); ));
......
...@@ -38,8 +38,8 @@ function setUp() { ...@@ -38,8 +38,8 @@ function setUp() {
function testCommentClasses() { function testCommentClasses() {
// Create all permutations for comments, users, and nodes. // Create all permutations for comments, users, and nodes.
$parameters = array( $parameters = array(
'node_uid' => array(0, $this->web_user->uid), 'node_uid' => array(0, $this->web_user->id()),
'comment_uid' => array(0, $this->web_user->uid, $this->admin_user->uid), 'comment_uid' => array(0, $this->web_user->id(), $this->admin_user->id()),
'comment_status' => array(COMMENT_PUBLISHED, COMMENT_NOT_PUBLISHED), 'comment_status' => array(COMMENT_PUBLISHED, COMMENT_NOT_PUBLISHED),
'user' => array('anonymous', 'authenticated', 'admin'), 'user' => array('anonymous', 'authenticated', 'admin'),
); );
...@@ -72,12 +72,12 @@ function testCommentClasses() { ...@@ -72,12 +72,12 @@ function testCommentClasses() {
case 'authenticated': case 'authenticated':
$this->drupalLogin($this->web_user); $this->drupalLogin($this->web_user);
$case['user_uid'] = $this->web_user->uid; $case['user_uid'] = $this->web_user->id();
break; break;
case 'admin': case 'admin':
$this->drupalLogin($this->admin_user); $this->drupalLogin($this->admin_user);
$case['user_uid'] = $this->admin_user->uid; $case['user_uid'] = $this->admin_user->id();
break; break;
} }