php drupal-check.phar modules/contrib/user_delete_reassign/
 3/3 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ --------------------------------------------------------------------------- 
  Line   user_delete_reassign.module                                                
 ------ --------------------------------------------------------------------------- 
  131    Call to deprecated method getUsername() of class Drupal\user\Entity\User.  
 ------ --------------------------------------------------------------------------- 

                                                                                                                        
 [ERROR] Found 1 error 

Comments

Sergiu Stici created an issue. See original summary.

sergiu stici’s picture

Status: Active » Needs review
StatusFileSize
new730 bytes

Here is the patch, please review.

joey-santiago’s picture

thanks Sergiu!
sure, i'll test it asap.

hkirsman’s picture

In the comments of getUsername() it says that there are 2 options: getAccountName() or getDisplayName()

  /**
   * Returns the unaltered login name of this account.
   *
   * @return string
   *   An unsanitized plain-text string with the name of this account that is
   *   used to log in. Only display this name to admins and to the user who owns
   *   this account, and only in the context of the name used to log in. For
   *   any other display purposes, use
   *   \Drupal\Core\Session\AccountInterface::getDisplayName() instead.
   *
   * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
   *   Use \Drupal\Core\Session\AccountInterface::getAccountName() or
   *   \Drupal\user\UserInterface::getDisplayName() instead.
   *
   * @see https://www.drupal.org/node/2572493
   */
  public function getUsername();

I've implemented hook_user_format_name_alter() and changed how the username looks wherever it's displayed. getAccountName() is ignoring that hook and just displays the username field.

Long story short, let's use getDisplayName() instead

sergiu stici’s picture

StatusFileSize
new730 bytes
hkirsman’s picture

  • Sergiu Stici authored f306559 on 8.x-1.x
    Issue #3072115 by Sergiu Stici, hkirsman: deprecated method getUsername...
hkirsman’s picture

Thank you @sergiu-stici!

hkirsman’s picture

Status: Needs review » Fixed
hkirsman’s picture

Status: Fixed » Closed (fixed)