Commit 2d1adba4 authored by webchick's avatar webchick

Issue #2061899 by joelpittet, m1r1k: Remove references to global in Comment module.

parent 8c59a993
......@@ -1276,7 +1276,6 @@ function comment_get_display_page($cid, $instance) {
* @param \Drupal\comment\CommentInterface $comment
*/
function comment_preview(CommentInterface $comment, array &$form_state) {
global $user;
$preview_build = array();
$entity = entity_load($comment->entity_type->value, $comment->entity_id->value);
......@@ -1285,8 +1284,8 @@ function comment_preview(CommentInterface $comment, array &$form_state) {
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()) {
......@@ -1514,13 +1513,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.
......
......@@ -218,10 +218,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.
......@@ -290,8 +288,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;
......
......@@ -100,7 +100,7 @@ public function query() {
}
public function preRender(&$values) {
global $user;
$user = \Drupal::currentUser();
if ($user->isAnonymous() || empty($values)) {
return;
}
......
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment