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

8.0.x
webchick 2013-12-10 22:58:02 -08:00
parent 8c59a99310
commit 2d1adba498
4 changed files with 8 additions and 12 deletions

View File

@ -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.

View File

@ -218,10 +218,8 @@ class Comment extends ContentEntityBase implements CommentInterface {
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 @@ class Comment extends ContentEntityBase implements CommentInterface {
}
// 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;

View File

@ -100,7 +100,7 @@ class NodeNewComments extends Numeric {
}
public function preRender(&$values) {
global $user;
$user = \Drupal::currentUser();
if ($user->isAnonymous() || empty($values)) {
return;
}

View File

@ -237,7 +237,7 @@ class ContentTranslationController implements ContentTranslationControllerInterf
// 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();