diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index fa38bfb..5305248 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1286,7 +1286,6 @@ function comment_get_display_page($cid, $instance) { * @param \Drupal\comment\CommentInterface $comment */ function comment_preview(CommentInterface $comment) { - global $user; $preview_build = array(); $entity = entity_load($comment->entity_type->value, $comment->entity_id->value); @@ -1295,8 +1294,8 @@ function comment_preview(CommentInterface $comment) { if (!empty($comment->name->value)) { $account = user_load_by_name($comment->name->value); } - elseif ($user->isAuthenticated() && empty($comment->is_anonymous)) { - $account = $user; + elseif (\Drupal::currentUser()->isAuthenticated() && empty($comment->is_anonymous)) { + $account = \Drupal::currentUser(); } if (!empty($account) && $account->isAuthenticated()) { @@ -1524,13 +1523,12 @@ function template_preprocess_comment(&$variables) { function theme_comment_post_forbidden($variables) { $entity = $variables['commented_entity']; $field_name = $variables['field_name']; - global $user; // Since this is expensive to compute, we cache it so that a page with many // comments only has to query the database once for all the links. $authenticated_post_comments = &drupal_static(__FUNCTION__, NULL); - if ($user->isAnonymous()) { + if (\Drupal::currentUser()->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. diff --git a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php index cf96a59..37cefc2 100644 --- a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php @@ -216,10 +216,8 @@ public function id() { public function preSave(EntityStorageControllerInterface $storage_controller) { parent::preSave($storage_controller); - $user = \Drupal::currentUser(); - if (!isset($this->status->value)) { - $this->status->value = $user->hasPermission('skip comment approval') ? COMMENT_PUBLISHED : COMMENT_NOT_PUBLISHED; + $this->status->value = \Drupal::currentUser()->hasPermission('skip comment approval') ? COMMENT_PUBLISHED : COMMENT_NOT_PUBLISHED; } if ($this->isNew()) { // Add the comment to database. This next section builds the thread field. @@ -288,8 +286,8 @@ 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->id() && $user->isAuthenticated()) { - $this->name->value = $user->getUsername(); + if ($this->uid->target_id === \Drupal::currentUser()->id() && \Drupal::currentUser()->isAuthenticated()) { + $this->name->value = \Drupal::currentUser()->getUsername(); } // Add the values which aren't passed into the function. $this->thread->value = $thread; diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeNewComments.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeNewComments.php index 3e36dff..b12ade0 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeNewComments.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/field/NodeNewComments.php @@ -93,7 +93,7 @@ public function query() { } public function preRender(&$values) { - global $user; + $user = \Drupal::currentUser(); if ($user->isAnonymous() || empty($values)) { return; } diff --git a/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php b/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php index 634043b..18192c6 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php @@ -237,7 +237,7 @@ public function entityFormAlter(array &$form, array &$form_state, EntityInterfac // Default to the anonymous user. $name = ''; if ($new_translation) { - $name = $GLOBALS['user']->getUsername(); + $name = \Drupal::currentUser()->getUsername(); } elseif ($entity->translation[$form_langcode]['uid']) { $name = user_load($entity->translation[$form_langcode]['uid'])->getUsername();