diff --git a/core/lib/Drupal/Core/Session/AccountInterface.php b/core/lib/Drupal/Core/Session/AccountInterface.php
index 1cf82dc..973ca3a 100644
--- a/core/lib/Drupal/Core/Session/AccountInterface.php
+++ b/core/lib/Drupal/Core/Session/AccountInterface.php
@@ -146,6 +146,11 @@ public function getAccountName();
public function getDisplayName();
/**
+ * {@inheritdoc}
+ */
+ public function getDisplayNameTruncated();
+
+ /**
* Returns the email address of this account.
*
* @return string
@@ -171,4 +176,16 @@ public function getTimeZone();
*/
public function getLastAccessedTime();
+ /**
+ * Returns the truncated display name of this account.
+ *
+ * @see getDisplayName()
+ *
+ * @return string|\Drupal\Component\Render\MarkupInterface
+ * Either a string that will be auto-escaped on output or a
+ * MarkupInterface object that is already HTML escaped. Either is safe
+ * to be printed within HTML fragments.
+ */
+ public function getDisplayNameTruncated();
+
}
diff --git a/core/lib/Drupal/Core/Session/UserSession.php b/core/lib/Drupal/Core/Session/UserSession.php
index f426803..fb99539 100644
--- a/core/lib/Drupal/Core/Session/UserSession.php
+++ b/core/lib/Drupal/Core/Session/UserSession.php
@@ -2,6 +2,8 @@
namespace Drupal\Core\Session;
+use Drupal\Component\Utility\Unicode;
+
/**
* An implementation of the user account interface for the global user.
*
@@ -177,6 +179,17 @@ public function getDisplayName() {
/**
* {@inheritdoc}
*/
+ public function getDisplayNameTruncated() {
+ $name = $this->getDisplayName();
+ if (Unicode::strlen($name) > 20) {
+ $name = Unicode::truncate($name, 15, FALSE, TRUE);
+ }
+ return $name;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function getEmail() {
return $this->mail;
}
diff --git a/core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php b/core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php
index b197a76..d3600a5 100644
--- a/core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php
+++ b/core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php
@@ -36,15 +36,15 @@ public function testBasicAuth() {
$account = $this->drupalCreateUser();
$url = Url::fromRoute('router_test.11');
- $this->basicAuthGet($url, $account->getUsername(), $account->pass_raw);
- $this->assertText($account->getUsername(), 'Account name is displayed.');
+ $this->basicAuthGet($url, $account->getDisplayName(), $account->pass_raw);
+ $this->assertText($account->getDisplayName(), 'Account name is displayed.');
$this->assertResponse('200', 'HTTP response is OK');
$this->mink->resetSessions();
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'));
$this->assertIdentical(strpos($this->drupalGetHeader('Cache-Control'), 'public'), FALSE, 'Cache-Control is not set to public');
- $this->basicAuthGet($url, $account->getUsername(), $this->randomMachineName());
- $this->assertNoText($account->getUsername(), 'Bad basic auth credentials do not authenticate the user.');
+ $this->basicAuthGet($url, $account->getDisplayName(), $this->randomMachineName());
+ $this->assertNoText($account->getDisplayName(), 'Bad basic auth credentials do not authenticate the user.');
$this->assertResponse('403', 'Access is not granted.');
$this->mink->resetSessions();
@@ -57,7 +57,7 @@ public function testBasicAuth() {
$account = $this->drupalCreateUser(['access administration pages']);
- $this->basicAuthGet(Url::fromRoute('system.admin'), $account->getUsername(), $account->pass_raw);
+ $this->basicAuthGet(Url::fromRoute('system.admin'), $account->getDisplayName(), $account->pass_raw);
$this->assertNoLink('Log out', 'User is not logged in');
$this->assertResponse('403', 'No basic authentication for routes not explicitly defining authentication providers.');
$this->mink->resetSessions();
@@ -67,7 +67,7 @@ public function testBasicAuth() {
$url = Url::fromRoute('router_test.10');
$this->drupalGet($url);
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS');
- $this->basicAuthGet($url, $account->getUsername(), $account->pass_raw);
+ $this->basicAuthGet($url, $account->getDisplayName(), $account->pass_raw);
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'));
$this->assertIdentical(strpos($this->drupalGetHeader('Cache-Control'), 'public'), FALSE, 'No page cache response when requesting a cached page with basic auth credentials.');
}
@@ -89,11 +89,11 @@ public function testGlobalLoginFloodControl() {
// Try 2 failed logins.
for ($i = 0; $i < 2; $i++) {
- $this->basicAuthGet($url, $incorrect_user->getUsername(), $incorrect_user->pass_raw);
+ $this->basicAuthGet($url, $incorrect_user->getDisplayName(), $incorrect_user->pass_raw);
}
// IP limit has reached to its limit. Even valid user credentials will fail.
- $this->basicAuthGet($url, $user->getUsername(), $user->pass_raw);
+ $this->basicAuthGet($url, $user->getDisplayName(), $user->pass_raw);
$this->assertResponse('403', 'Access is blocked because of IP based flood prevention.');
}
@@ -114,24 +114,24 @@ public function testPerUserLoginFloodControl() {
$url = Url::fromRoute('router_test.11');
// Try a failed login.
- $this->basicAuthGet($url, $incorrect_user->getUsername(), $incorrect_user->pass_raw);
+ $this->basicAuthGet($url, $incorrect_user->getDisplayName(), $incorrect_user->pass_raw);
// A successful login will reset the per-user flood control count.
- $this->basicAuthGet($url, $user->getUsername(), $user->pass_raw);
+ $this->basicAuthGet($url, $user->getDisplayName(), $user->pass_raw);
$this->assertResponse('200', 'Per user flood prevention gets reset on a successful login.');
// Try 2 failed logins for a user. They will trigger flood control.
for ($i = 0; $i < 2; $i++) {
- $this->basicAuthGet($url, $incorrect_user->getUsername(), $incorrect_user->pass_raw);
+ $this->basicAuthGet($url, $incorrect_user->getDisplayName(), $incorrect_user->pass_raw);
}
// Now the user account is blocked.
- $this->basicAuthGet($url, $user->getUsername(), $user->pass_raw);
+ $this->basicAuthGet($url, $user->getDisplayName(), $user->pass_raw);
$this->assertResponse('403', 'The user account is blocked due to per user flood prevention.');
// Try one successful attempt for a different user, it should not trigger
// any flood control.
- $this->basicAuthGet($url, $user2->getUsername(), $user2->pass_raw);
+ $this->basicAuthGet($url, $user2->getDisplayName(), $user2->pass_raw);
$this->assertResponse('200', 'Per user flood prevention does not block access for other users.');
}
@@ -145,8 +145,8 @@ public function testLocale() {
$account = $this->drupalCreateUser();
$url = Url::fromRoute('router_test.11');
- $this->basicAuthGet($url, $account->getUsername(), $account->pass_raw);
- $this->assertText($account->getUsername(), 'Account name is displayed.');
+ $this->basicAuthGet($url, $account->getDisplayName(), $account->pass_raw);
+ $this->assertText($account->getDisplayName(), 'Account name is displayed.');
$this->assertResponse('200', 'HTTP response is OK');
}
@@ -169,13 +169,13 @@ public function testUnauthorizedErrorMessage() {
$this->assertText('Access denied', "A user friendly access denied message is displayed");
// Case when wrong credentials are passed.
- $this->basicAuthGet($url, $account->getUsername(), $this->randomMachineName());
+ $this->basicAuthGet($url, $account->getDisplayName(), $this->randomMachineName());
$this->assertResponse('403', 'The user is blocked when wrong credentials are passed.');
$this->assertText('Access denied', "A user friendly access denied message is displayed");
// Case when correct credentials but hasn't access to the route.
$url = Url::fromRoute('router_test.15');
- $this->basicAuthGet($url, $account->getUsername(), $account->pass_raw);
+ $this->basicAuthGet($url, $account->getDisplayName(), $account->pass_raw);
$this->assertResponse('403', 'The used authentication method is not allowed on this route.');
$this->assertText('Access denied', "A user friendly access denied message is displayed");
}
@@ -193,7 +193,7 @@ public function testControllerNotCalledBeforeAuth() {
$this->assertRaw('nope');
$account = $this->drupalCreateUser();
- $this->basicAuthGet('/basic_auth_test/state/modify', $account->getUsername(), $account->pass_raw);
+ $this->basicAuthGet('/basic_auth_test/state/modify', $account->getDisplayName(), $account->pass_raw);
$this->assertResponse(200);
$this->assertRaw('Done');
diff --git a/core/modules/block/src/Tests/BlockUiTest.php b/core/modules/block/src/Tests/BlockUiTest.php
index d4ebda4..a5594d2 100644
--- a/core/modules/block/src/Tests/BlockUiTest.php
+++ b/core/modules/block/src/Tests/BlockUiTest.php
@@ -209,7 +209,7 @@ public function testContextAwareUnsatisfiedBlocks() {
* Tests the behavior of context-aware blocks.
*/
public function testContextAwareBlocks() {
- $expected_text = '
' . \Drupal::currentUser()->getUsername() . '
';
+ $expected_text = '' . \Drupal::currentUser()->getDisplayName() . '
';
$this->drupalGet('');
$this->assertNoText('Test context-aware block');
$this->assertNoRaw($expected_text);
diff --git a/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php
index 7db350d..c484561 100644
--- a/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php
+++ b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php
@@ -28,7 +28,7 @@ public function build() {
return [
'#prefix' => '',
'#suffix' => '
',
- '#markup' => $user ? $user->getUsername() : 'No context mapping selected.' ,
+ '#markup' => $user ? $user->getDisplayName() : 'No context mapping selected.' ,
];
}
diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php
index a5f1966..9f6d555 100644
--- a/core/modules/comment/src/Entity/Comment.php
+++ b/core/modules/comment/src/Entity/Comment.php
@@ -149,7 +149,7 @@ public function preSave(EntityStorageInterface $storage) {
// We test the value with '===' because we need to modify anonymous
// users as well.
if ($this->getOwnerId() === \Drupal::currentUser()->id() && \Drupal::currentUser()->isAuthenticated()) {
- $this->setAuthorName(\Drupal::currentUser()->getUsername());
+ $this->setAuthorName(\Drupal::currentUser()->getDisplayName());
}
$this->setThread($thread);
if (!$this->getHostname()) {
diff --git a/core/modules/comment/src/Plugin/Validation/Constraint/CommentNameConstraintValidator.php b/core/modules/comment/src/Plugin/Validation/Constraint/CommentNameConstraintValidator.php
index 87cdaf9..9e45188 100644
--- a/core/modules/comment/src/Plugin/Validation/Constraint/CommentNameConstraintValidator.php
+++ b/core/modules/comment/src/Plugin/Validation/Constraint/CommentNameConstraintValidator.php
@@ -65,7 +65,7 @@ public function validate($entity, Constraint $constraint) {
// If an author name and owner are given, make sure they match.
elseif (isset($author_name) && $author_name !== '' && $owner_id) {
$owner = $this->userStorage->load($owner_id);
- if ($owner->getUsername() != $author_name) {
+ if ($owner->getDisplayName() != $author_name) {
$this->context->buildViolation($constraint->messageMatch)
->atPath('name')
->addViolation();
diff --git a/core/modules/comment/src/Tests/CommentAnonymousTest.php b/core/modules/comment/src/Tests/CommentAnonymousTest.php
index d60c073..4a44f14 100644
--- a/core/modules/comment/src/Tests/CommentAnonymousTest.php
+++ b/core/modules/comment/src/Tests/CommentAnonymousTest.php
@@ -67,12 +67,12 @@ public function testAnonymous() {
// Ensure anonymous users cannot post in the name of registered users.
$edit = [
- 'name' => $this->adminUser->getUsername(),
+ 'name' => $this->adminUser->getDisplayName(),
'comment_body[0][value]' => $this->randomMachineName(),
];
$this->drupalPostForm('comment/reply/node/' . $this->node->id() . '/comment', $edit, t('Save'));
$this->assertRaw(t('The name you used (%name) belongs to a registered user.', [
- '%name' => $this->adminUser->getUsername(),
+ '%name' => $this->adminUser->getDisplayName(),
]));
// Allow contact info.
@@ -98,14 +98,14 @@ public function testAnonymous() {
// Ensure anonymous users cannot post in the name of registered users.
$edit = [
- 'name' => $this->adminUser->getUsername(),
+ 'name' => $this->adminUser->getDisplayName(),
'mail' => $this->randomMachineName() . '@example.com',
'subject[0][value]' => $this->randomMachineName(),
'comment_body[0][value]' => $this->randomMachineName(),
];
$this->drupalPostForm('comment/reply/node/' . $this->node->id() . '/comment', $edit, t('Save'));
$this->assertRaw(t('The name you used (%name) belongs to a registered user.', [
- '%name' => $this->adminUser->getUsername(),
+ '%name' => $this->adminUser->getDisplayName(),
]));
// Require contact info.
diff --git a/core/modules/comment/src/Tests/CommentInterfaceTest.php b/core/modules/comment/src/Tests/CommentInterfaceTest.php
index 6f67ca8..bef73a6 100644
--- a/core/modules/comment/src/Tests/CommentInterfaceTest.php
+++ b/core/modules/comment/src/Tests/CommentInterfaceTest.php
@@ -109,8 +109,8 @@ public function testCommentInterface() {
// Test changing the comment author to a verified user.
$this->drupalGet('comment/' . $comment->id() . '/edit');
- $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->getSubject(), ['uid' => $this->webUser->getUsername() . ' (' . $this->webUser->id() . ')']);
- $this->assertTrue($comment->getAuthorName() == $this->webUser->getUsername() && $comment->getOwnerId() == $this->webUser->id(), 'Comment author successfully changed to a registered user.');
+ $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->getSubject(), ['uid' => $this->webUser->getDisplayName() . ' (' . $this->webUser->id() . ')']);
+ $this->assertTrue($comment->getAuthorName() == $this->webUser->getDisplayName() && $comment->getOwnerId() == $this->webUser->id(), 'Comment author successfully changed to a registered user.');
$this->drupalLogout();
diff --git a/core/modules/comment/src/Tests/CommentPreviewTest.php b/core/modules/comment/src/Tests/CommentPreviewTest.php
index 1b07fe6..d96ff82 100644
--- a/core/modules/comment/src/Tests/CommentPreviewTest.php
+++ b/core/modules/comment/src/Tests/CommentPreviewTest.php
@@ -135,7 +135,7 @@ public function testCommentEditPreviewSave() {
$date = new DrupalDateTime('2008-03-02 17:23');
$edit['subject[0][value]'] = $this->randomMachineName(8);
$edit['comment_body[0][value]'] = $this->randomMachineName(16);
- $edit['uid'] = $web_user->getUsername() . ' (' . $web_user->id() . ')';
+ $edit['uid'] = $web_user->getDisplayName() . ' (' . $web_user->id() . ')';
$edit['date[date]'] = $date->format('Y-m-d');
$edit['date[time]'] = $date->format('H:i:s');
$raw_date = $date->getTimestamp();
@@ -149,7 +149,7 @@ public function testCommentEditPreviewSave() {
$this->assertTitle(t('Preview comment | Drupal'), 'Page title is "Preview comment".');
$this->assertText($edit['subject[0][value]'], 'Subject displayed.');
$this->assertText($edit['comment_body[0][value]'], 'Comment displayed.');
- $this->assertText($web_user->getUsername(), 'Author displayed.');
+ $this->assertText($web_user->getDisplayName(), 'Author displayed.');
$this->assertText($expected_text_date, 'Date displayed.');
// Check that the subject, comment, author and date fields are displayed with the correct values.
diff --git a/core/modules/comment/src/Tests/CommentTranslationUITest.php b/core/modules/comment/src/Tests/CommentTranslationUITest.php
index 4613d66..caa918b 100644
--- a/core/modules/comment/src/Tests/CommentTranslationUITest.php
+++ b/core/modules/comment/src/Tests/CommentTranslationUITest.php
@@ -162,7 +162,7 @@ protected function doTestAuthoringInfo() {
'created' => REQUEST_TIME - mt_rand(0, 1000),
];
$edit = [
- 'uid' => $user->getUsername() . ' (' . $user->id() . ')',
+ 'uid' => $user->getDisplayName() . ' (' . $user->id() . ')',
'date[date]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d'),
'date[time]' => format_date($values[$langcode]['created'], 'custom', 'H:i:s'),
];
diff --git a/core/modules/comment/tests/src/Kernel/CommentFieldAccessTest.php b/core/modules/comment/tests/src/Kernel/CommentFieldAccessTest.php
index 5046353..8e5f67e 100644
--- a/core/modules/comment/tests/src/Kernel/CommentFieldAccessTest.php
+++ b/core/modules/comment/tests/src/Kernel/CommentFieldAccessTest.php
@@ -211,12 +211,12 @@ public function testAccessToAdministrativeFields() {
$may_view = $set['comment']->{$field}->access('view', $set['user']);
$may_update = $set['comment']->{$field}->access('edit', $set['user']);
$this->assertTrue($may_view, SafeMarkup::format('User @user can view field @field on comment @comment', [
- '@user' => $set['user']->getUsername(),
+ '@user' => $set['user']->getDisplayName(),
'@comment' => $set['comment']->getSubject(),
'@field' => $field,
]));
$this->assertEqual($may_update, $set['user']->hasPermission('administer comments'), SafeMarkup::format('User @user @state update field @field on comment @comment', [
- '@user' => $set['user']->getUsername(),
+ '@user' => $set['user']->getDisplayName(),
'@state' => $may_update ? 'can' : 'cannot',
'@comment' => $set['comment']->getSubject(),
'@field' => $field,
@@ -228,7 +228,7 @@ public function testAccessToAdministrativeFields() {
foreach ($permutations as $set) {
$may_update = $set['comment']->access('update', $set['user']) && $set['comment']->subject->access('edit', $set['user']);
$this->assertEqual($may_update, $set['user']->hasPermission('administer comments') || ($set['user']->hasPermission('edit own comments') && $set['user']->id() == $set['comment']->getOwnerId()), SafeMarkup::format('User @user @state update field subject on comment @comment', [
- '@user' => $set['user']->getUsername(),
+ '@user' => $set['user']->getDisplayName(),
'@state' => $may_update ? 'can' : 'cannot',
'@comment' => $set['comment']->getSubject(),
]));
@@ -250,13 +250,13 @@ public function testAccessToAdministrativeFields() {
$state = 'can';
}
$this->assertEqual($may_view, $view_access, SafeMarkup::format('User @user @state view field @field on comment @comment', [
- '@user' => $set['user']->getUsername(),
+ '@user' => $set['user']->getDisplayName(),
'@comment' => $set['comment']->getSubject(),
'@field' => $field,
'@state' => $state,
]));
$this->assertFalse($may_update, SafeMarkup::format('User @user @state update field @field on comment @comment', [
- '@user' => $set['user']->getUsername(),
+ '@user' => $set['user']->getDisplayName(),
'@state' => $may_update ? 'can' : 'cannot',
'@comment' => $set['comment']->getSubject(),
'@field' => $field,
@@ -271,12 +271,12 @@ public function testAccessToAdministrativeFields() {
$may_view = $set['comment']->{$field}->access('view', $set['user']);
$may_update = $set['comment']->{$field}->access('edit', $set['user']);
$this->assertEqual($may_view, TRUE, SafeMarkup::format('User @user can view field @field on comment @comment', [
- '@user' => $set['user']->getUsername(),
+ '@user' => $set['user']->getDisplayName(),
'@comment' => $set['comment']->getSubject(),
'@field' => $field,
]));
$this->assertEqual($may_update, $set['user']->hasPermission('post comments') && $set['comment']->isNew(), SafeMarkup::format('User @user @state update field @field on comment @comment', [
- '@user' => $set['user']->getUsername(),
+ '@user' => $set['user']->getDisplayName(),
'@state' => $may_update ? 'can' : 'cannot',
'@comment' => $set['comment']->getSubject(),
'@field' => $field,
@@ -298,7 +298,7 @@ public function testAccessToAdministrativeFields() {
$set['user']->hasPermission('post comments') &&
$set['comment']->getFieldName() == 'comment_other'
), SafeMarkup::format('User @user @state update field @field on comment @comment', [
- '@user' => $set['user']->getUsername(),
+ '@user' => $set['user']->getDisplayName(),
'@state' => $may_update ? 'can' : 'cannot',
'@comment' => $set['comment']->getSubject(),
'@field' => $field,
diff --git a/core/modules/comment/tests/src/Kernel/Views/CommentViewsFieldAccessTest.php b/core/modules/comment/tests/src/Kernel/Views/CommentViewsFieldAccessTest.php
index f807c58..a294f1c 100644
--- a/core/modules/comment/tests/src/Kernel/Views/CommentViewsFieldAccessTest.php
+++ b/core/modules/comment/tests/src/Kernel/Views/CommentViewsFieldAccessTest.php
@@ -67,7 +67,7 @@ public function testCommentFields() {
$this->assertFieldAccess('comment', 'name', 'anonymous');
$this->assertFieldAccess('comment', 'mail', 'test@example.com');
$this->assertFieldAccess('comment', 'homepage', 'https://example.com');
- $this->assertFieldAccess('comment', 'uid', $user->getUsername());
+ $this->assertFieldAccess('comment', 'uid', $user->getDisplayName());
// $this->assertFieldAccess('comment', 'created', \Drupal::service('date.formatter')->format(123456));
// $this->assertFieldAccess('comment', 'changed', \Drupal::service('date.formatter')->format(REQUEST_TIME));
$this->assertFieldAccess('comment', 'status', 'On');
diff --git a/core/modules/contact/src/MailHandler.php b/core/modules/contact/src/MailHandler.php
index b57864c..4cd0a32 100644
--- a/core/modules/contact/src/MailHandler.php
+++ b/core/modules/contact/src/MailHandler.php
@@ -134,16 +134,16 @@ public function sendMailMessages(MessageInterface $message, AccountInterface $se
if (!$message->isPersonal()) {
$this->logger->notice('%sender-name (@sender-from) sent an email regarding %contact_form.', [
- '%sender-name' => $sender_cloned->getUsername(),
+ '%sender-name' => $sender_cloned->getDisplayName(),
'@sender-from' => $sender_cloned->getEmail(),
'%contact_form' => $contact_form->label(),
]);
}
else {
$this->logger->notice('%sender-name (@sender-from) sent %recipient-name an email.', [
- '%sender-name' => $sender_cloned->getUsername(),
+ '%sender-name' => $sender_cloned->getDisplayName(),
'@sender-from' => $sender_cloned->getEmail(),
- '%recipient-name' => $message->getPersonalRecipient()->getUsername(),
+ '%recipient-name' => $message->getPersonalRecipient()->getDisplayName(),
]);
}
}
diff --git a/core/modules/contact/tests/src/Functional/ContactPersonalTest.php b/core/modules/contact/tests/src/Functional/ContactPersonalTest.php
index 7e6ecad..ebb6765 100644
--- a/core/modules/contact/tests/src/Functional/ContactPersonalTest.php
+++ b/core/modules/contact/tests/src/Functional/ContactPersonalTest.php
@@ -65,7 +65,7 @@ protected function setUp() {
*/
public function testSendPersonalContactMessage() {
// Ensure that the web user's email needs escaping.
- $mail = $this->webUser->getUsername() . '&escaped@example.com';
+ $mail = $this->webUser->getDisplayName() . '&escaped@example.com';
$this->webUser->setEmail($mail)->save();
$this->drupalLogin($this->webUser);
@@ -98,7 +98,7 @@ public function testSendPersonalContactMessage() {
$placeholders = [
'@sender_name' => $this->webUser->username,
'@sender_email' => $this->webUser->getEmail(),
- '@recipient_name' => $this->contactUser->getUsername()
+ '@recipient_name' => $this->contactUser->getDisplayName()
];
$this->assertRaw(SafeMarkup::format('@sender_name (@sender_email) sent @recipient_name an email.', $placeholders));
// Ensure an unescaped version of the email does not exist anywhere.
diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php
index c1688b9..2aa0434 100644
--- a/core/modules/content_translation/src/ContentTranslationHandler.php
+++ b/core/modules/content_translation/src/ContentTranslationHandler.php
@@ -615,7 +615,7 @@ public function entityFormValidate($form, FormStateInterface $form_state) {
$translation = $form_state->getValue('content_translation');
// Validate the "authored by" field.
if (!empty($translation['uid']) && !($account = User::load($translation['uid']))) {
- $form_state->setErrorByName('content_translation][uid', t('The translation authoring username %name does not exist.', ['%name' => $account->getUsername()]));
+ $form_state->setErrorByName('content_translation][uid', t('The translation authoring username %name does not exist.', ['%name' => $account->getDisplayName()]));
}
// Validate the "authored on" field.
if (!empty($translation['created']) && strtotime($translation['created']) === FALSE) {
diff --git a/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php b/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php
index e7a7dfc..ba35cb5 100644
--- a/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php
+++ b/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php
@@ -326,7 +326,7 @@ protected function doTestAuthoringInfo() {
'created' => REQUEST_TIME - mt_rand(0, 1000),
];
$edit = [
- 'content_translation[uid]' => $user->getUsername(),
+ 'content_translation[uid]' => $user->getDisplayName(),
'content_translation[created]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d H:i:s O'),
];
$url = $entity->urlInfo('edit-form', ['language' => ConfigurableLanguage::load($langcode)]);
diff --git a/core/modules/content_translation/src/Tests/ContentTranslationWorkflowsTest.php b/core/modules/content_translation/src/Tests/ContentTranslationWorkflowsTest.php
index 66469eb..de7cc09 100644
--- a/core/modules/content_translation/src/Tests/ContentTranslationWorkflowsTest.php
+++ b/core/modules/content_translation/src/Tests/ContentTranslationWorkflowsTest.php
@@ -151,7 +151,7 @@ public function testWorkflows() {
protected function doTestWorkflows(UserInterface $user, $expected_status) {
$default_langcode = $this->langcodes[0];
$languages = $this->container->get('language_manager')->getLanguages();
- $args = ['@user_label' => $user->getUsername()];
+ $args = ['@user_label' => $user->getDisplayName()];
$options = ['language' => $languages[$default_langcode], 'absolute' => TRUE];
$this->drupalLogin($user);
diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php
index 370a6ed..c2a6997 100644
--- a/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php
+++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php
@@ -323,7 +323,7 @@ protected function doTestAuthoringInfo() {
'created' => REQUEST_TIME - mt_rand(0, 1000),
];
$edit = [
- 'content_translation[uid]' => $user->getUsername(),
+ 'content_translation[uid]' => $user->getDisplayName(),
'content_translation[created]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d H:i:s O'),
];
$url = $entity->urlInfo('edit-form', ['language' => ConfigurableLanguage::load($langcode)]);
diff --git a/core/modules/dblog/src/Tests/DbLogTest.php b/core/modules/dblog/src/Tests/DbLogTest.php
index 79cc038..30a453a 100644
--- a/core/modules/dblog/src/Tests/DbLogTest.php
+++ b/core/modules/dblog/src/Tests/DbLogTest.php
@@ -397,7 +397,7 @@ private function doUser() {
$ids[] = $row->wid;
}
$count_before = (isset($ids)) ? count($ids) : 0;
- $this->assertTrue($count_before > 0, format_string('DBLog contains @count records for @name', ['@count' => $count_before, '@name' => $user->getUsername()]));
+ $this->assertTrue($count_before > 0, format_string('DBLog contains @count records for @name', ['@count' => $count_before, '@name' => $user->getDisplayName()]));
// Log in the admin user.
$this->drupalLogin($this->adminUser);
diff --git a/core/modules/language/src/Tests/LanguageUrlRewritingTest.php b/core/modules/language/src/Tests/LanguageUrlRewritingTest.php
index 65ae64c..0f98001 100644
--- a/core/modules/language/src/Tests/LanguageUrlRewritingTest.php
+++ b/core/modules/language/src/Tests/LanguageUrlRewritingTest.php
@@ -61,7 +61,7 @@ public function testUrlRewritingEdgeCases() {
// Check that URL rewriting is not applied to subrequests.
$this->drupalGet('language_test/subrequest');
- $this->assertText($this->webUser->getUsername(), 'Page correctly retrieved');
+ $this->assertText($this->webUser->getDisplayName(), 'Page correctly retrieved');
}
/**
diff --git a/core/modules/node/src/Tests/NodeAccessBaseTableTest.php b/core/modules/node/src/Tests/NodeAccessBaseTableTest.php
index 8eb9c9e..84d426b 100644
--- a/core/modules/node/src/Tests/NodeAccessBaseTableTest.php
+++ b/core/modules/node/src/Tests/NodeAccessBaseTableTest.php
@@ -100,7 +100,7 @@ public function testNodeAccessBasic() {
$this->drupalLogin($this->webUser);
foreach ([0 => 'Public', 1 => 'Private'] as $is_private => $type) {
$edit = [
- 'title[0][value]' => t('@private_public Article created by @user', ['@private_public' => $type, '@user' => $this->webUser->getUsername()]),
+ 'title[0][value]' => t('@private_public Article created by @user', ['@private_public' => $type, '@user' => $this->webUser->getDisplayName()]),
];
if ($is_private) {
$edit['private[0][value]'] = TRUE;
diff --git a/core/modules/node/src/Tests/NodeEditFormTest.php b/core/modules/node/src/Tests/NodeEditFormTest.php
index ed8b34a..f694c1e 100644
--- a/core/modules/node/src/Tests/NodeEditFormTest.php
+++ b/core/modules/node/src/Tests/NodeEditFormTest.php
@@ -227,7 +227,7 @@ protected function checkVariousAuthoredByValues(NodeInterface $node, $form_eleme
// Change the authored by field to another user's name (that is not
// logged in).
- $edit[$form_element_name] = $this->webUser->getUsername();
+ $edit[$form_element_name] = $this->webUser->getDisplayName();
$this->drupalPostForm(NULL, $edit, t('Save and keep published'));
$this->nodeStorage->resetCache([$node->id()]);
$node = $this->nodeStorage->load($node->id());
diff --git a/core/modules/node/src/Tests/NodeTranslationUITest.php b/core/modules/node/src/Tests/NodeTranslationUITest.php
index a01c4d5..a62ef5e 100644
--- a/core/modules/node/src/Tests/NodeTranslationUITest.php
+++ b/core/modules/node/src/Tests/NodeTranslationUITest.php
@@ -204,7 +204,7 @@ protected function doTestAuthoringInfo() {
'promote' => (bool) mt_rand(0, 1),
];
$edit = [
- 'uid[0][target_id]' => $user->getUsername(),
+ 'uid[0][target_id]' => $user->getDisplayName(),
'created[0][value][date]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d'),
'created[0][value][time]' => format_date($values[$langcode]['created'], 'custom', 'H:i:s'),
'sticky[value]' => $values[$langcode]['sticky'],
diff --git a/core/modules/node/src/Tests/Views/FilterNodeAccessTest.php b/core/modules/node/src/Tests/Views/FilterNodeAccessTest.php
index dba4419..f22060f 100644
--- a/core/modules/node/src/Tests/Views/FilterNodeAccessTest.php
+++ b/core/modules/node/src/Tests/Views/FilterNodeAccessTest.php
@@ -55,7 +55,7 @@ protected function setUp() {
'value' => $type . ' node',
'format' => filter_default_format(),
]],
- 'title' => t('@private_public Article created by @user', ['@private_public' => $type, '@user' => $web_user->getUsername()]),
+ 'title' => t('@private_public Article created by @user', ['@private_public' => $type, '@user' => $web_user->getDisplayName()]),
'type' => 'article',
'uid' => $web_user->id(),
'private' => (bool) $is_private,
@@ -74,38 +74,38 @@ public function testFilterNodeAccess() {
$this->drupalLogin($this->users[0]);
$this->drupalGet('test_filter_node_access');
// Test that the private node of the current user is shown.
- $this->assertText('Private Article created by ' . $this->users[0]->getUsername());
+ $this->assertText('Private Article created by ' . $this->users[0]->getDisplayName());
// Test that the private node of the other use isn't shown.
- $this->assertNoText('Private Article created by ' . $this->users[1]->getUsername());
+ $this->assertNoText('Private Article created by ' . $this->users[1]->getDisplayName());
// Test that both public nodes are shown.
- $this->assertText('Public Article created by ' . $this->users[0]->getUsername());
- $this->assertText('Public Article created by ' . $this->users[1]->getUsername());
+ $this->assertText('Public Article created by ' . $this->users[0]->getDisplayName());
+ $this->assertText('Public Article created by ' . $this->users[1]->getDisplayName());
// Switch users and test the other private node is shown.
$this->drupalLogin($this->users[1]);
$this->drupalGet('test_filter_node_access');
// Test that the private node of the current user is shown.
- $this->assertText('Private Article created by ' . $this->users[1]->getUsername());
+ $this->assertText('Private Article created by ' . $this->users[1]->getDisplayName());
// Test that the private node of the other use isn't shown.
- $this->assertNoText('Private Article created by ' . $this->users[0]->getUsername());
+ $this->assertNoText('Private Article created by ' . $this->users[0]->getDisplayName());
// Test that a user with administer nodes permission can't see all nodes.
$administer_nodes_user = $this->drupalCreateUser(['access content', 'administer nodes']);
$this->drupalLogin($administer_nodes_user);
$this->drupalGet('test_filter_node_access');
- $this->assertNoText('Private Article created by ' . $this->users[0]->getUsername());
- $this->assertNoText('Private Article created by ' . $this->users[1]->getUsername());
- $this->assertText('Public Article created by ' . $this->users[0]->getUsername());
- $this->assertText('Public Article created by ' . $this->users[1]->getUsername());
+ $this->assertNoText('Private Article created by ' . $this->users[0]->getDisplayName());
+ $this->assertNoText('Private Article created by ' . $this->users[1]->getDisplayName());
+ $this->assertText('Public Article created by ' . $this->users[0]->getDisplayName());
+ $this->assertText('Public Article created by ' . $this->users[1]->getDisplayName());
// Test that a user with bypass node access can see all nodes.
$bypass_access_user = $this->drupalCreateUser(['access content', 'bypass node access']);
$this->drupalLogin($bypass_access_user);
$this->drupalGet('test_filter_node_access');
- $this->assertText('Private Article created by ' . $this->users[0]->getUsername());
- $this->assertText('Private Article created by ' . $this->users[1]->getUsername());
- $this->assertText('Public Article created by ' . $this->users[0]->getUsername());
- $this->assertText('Public Article created by ' . $this->users[1]->getUsername());
+ $this->assertText('Private Article created by ' . $this->users[0]->getDisplayName());
+ $this->assertText('Private Article created by ' . $this->users[1]->getDisplayName());
+ $this->assertText('Public Article created by ' . $this->users[0]->getDisplayName());
+ $this->assertText('Public Article created by ' . $this->users[1]->getDisplayName());
}
}
diff --git a/core/modules/node/tests/src/Functional/NodeCreationTest.php b/core/modules/node/tests/src/Functional/NodeCreationTest.php
index 4d24901..a82a0a5 100644
--- a/core/modules/node/tests/src/Functional/NodeCreationTest.php
+++ b/core/modules/node/tests/src/Functional/NodeCreationTest.php
@@ -60,7 +60,7 @@ public function testNodeCreation() {
// Verify that pages do not show submitted information by default.
$this->drupalGet('node/' . $node->id());
- $this->assertNoText($node->getOwner()->getUsername());
+ $this->assertNoText($node->getOwner()->getDisplayName());
$this->assertNoText(format_date($node->getCreatedTime()));
// Change the node type setting to show submitted by information.
@@ -70,7 +70,7 @@ public function testNodeCreation() {
$node_type->save();
$this->drupalGet('node/' . $node->id());
- $this->assertText($node->getOwner()->getUsername());
+ $this->assertText($node->getOwner()->getDisplayName());
$this->assertText(format_date($node->getCreatedTime()));
// Check if the node revision checkbox is not rendered on node creation form.
diff --git a/core/modules/node/tests/src/Kernel/NodeTokenReplaceTest.php b/core/modules/node/tests/src/Kernel/NodeTokenReplaceTest.php
index dd39b6d..e155722 100644
--- a/core/modules/node/tests/src/Kernel/NodeTokenReplaceTest.php
+++ b/core/modules/node/tests/src/Kernel/NodeTokenReplaceTest.php
@@ -69,9 +69,9 @@ public function testNodeTokenReplacement() {
$tests['[node:langcode]'] = $node->language()->getId();
$tests['[node:url]'] = $node->url('canonical', $url_options);
$tests['[node:edit-url]'] = $node->url('edit-form', $url_options);
- $tests['[node:author]'] = $account->getUsername();
+ $tests['[node:author]'] = $account->getDisplayName();
$tests['[node:author:uid]'] = $node->getOwnerId();
- $tests['[node:author:name]'] = $account->getUsername();
+ $tests['[node:author:name]'] = $account->getDisplayName();
$tests['[node:created:since]'] = \Drupal::service('date.formatter')->formatTimeDiffSince($node->getCreatedTime(), ['langcode' => $this->interfaceLanguage->getId()]);
$tests['[node:changed:since]'] = \Drupal::service('date.formatter')->formatTimeDiffSince($node->getChangedTime(), ['langcode' => $this->interfaceLanguage->getId()]);
diff --git a/core/modules/node/tests/src/Kernel/Views/NodeViewsFieldAccessTest.php b/core/modules/node/tests/src/Kernel/Views/NodeViewsFieldAccessTest.php
index 7c68e88..3f6630c 100644
--- a/core/modules/node/tests/src/Kernel/Views/NodeViewsFieldAccessTest.php
+++ b/core/modules/node/tests/src/Kernel/Views/NodeViewsFieldAccessTest.php
@@ -60,7 +60,7 @@ public function testNodeFields() {
$this->assertFieldAccess('node', 'type', $node->type->entity->label());
$this->assertFieldAccess('node', 'langcode', $node->language()->getName());
$this->assertFieldAccess('node', 'title', 'Test title');
- $this->assertFieldAccess('node', 'uid', $user->getUsername());
+ $this->assertFieldAccess('node', 'uid', $user->getDisplayName());
// @todo Don't we want to display Published / Unpublished by default,
// see https://www.drupal.org/node/2465623
$this->assertFieldAccess('node', 'status', 'On');
diff --git a/core/modules/rdf/src/Tests/CommentAttributesTest.php b/core/modules/rdf/src/Tests/CommentAttributesTest.php
index 8ca5798..ccff925 100644
--- a/core/modules/rdf/src/Tests/CommentAttributesTest.php
+++ b/core/modules/rdf/src/Tests/CommentAttributesTest.php
@@ -154,7 +154,7 @@ public function testCommentRdfAuthorMarkup() {
// Ensure that the author link still works properly after the author output
// is modified by the RDF module.
$this->drupalGet('node/' . $this->node->id());
- $this->assertLink($this->webUser->getUsername());
+ $this->assertLink($this->webUser->getDisplayName());
$this->assertLinkByHref('user/' . $this->webUser->id());
}
@@ -320,7 +320,7 @@ public function _testBasicCommentRdfaMarkup($graph, CommentInterface $comment, $
}
// Author name.
- $name = empty($account["name"]) ? $this->webUser->getUsername() : $account["name"] . " (not verified)";
+ $name = empty($account["name"]) ? $this->webUser->getDisplayName() : $account["name"] . " (not verified)";
$expected_value = [
'type' => 'literal',
'value' => $name,
diff --git a/core/modules/rdf/tests/src/Functional/StandardProfileTest.php b/core/modules/rdf/tests/src/Functional/StandardProfileTest.php
index 76ae39b..c341352 100644
--- a/core/modules/rdf/tests/src/Functional/StandardProfileTest.php
+++ b/core/modules/rdf/tests/src/Functional/StandardProfileTest.php
@@ -477,7 +477,7 @@ protected function assertRdfaNodeCommentProperties($graph) {
// Comment author name.
$expected_value = [
'type' => 'literal',
- 'value' => $this->webUser->getUsername(),
+ 'value' => $this->webUser->getDisplayName(),
];
$this->assertTrue($graph->hasProperty($this->commenterUri, 'http://schema.org/name', $expected_value), 'Comment author name was found (schema:name).');
}
diff --git a/core/modules/rdf/tests/src/Functional/UserAttributesTest.php b/core/modules/rdf/tests/src/Functional/UserAttributesTest.php
index 7e98286..25f7298 100644
--- a/core/modules/rdf/tests/src/Functional/UserAttributesTest.php
+++ b/core/modules/rdf/tests/src/Functional/UserAttributesTest.php
@@ -73,7 +73,7 @@ public function testUserAttributesInMarkup() {
// User name.
$expected_value = [
'type' => 'literal',
- 'value' => $author->getUsername(),
+ 'value' => $author->getDisplayName(),
];
$this->assertTrue($graph->hasProperty($account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).');
@@ -98,7 +98,7 @@ public function testUserAttributesInMarkup() {
// User name.
$expected_value = [
'type' => 'literal',
- 'value' => $author->getUsername(),
+ 'value' => $author->getDisplayName(),
];
$this->assertTrue($graph->hasProperty($account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).');
diff --git a/core/modules/rest/src/Tests/Views/StyleSerializerTest.php b/core/modules/rest/src/Tests/Views/StyleSerializerTest.php
index 83a1548..f1fccc3 100644
--- a/core/modules/rest/src/Tests/Views/StyleSerializerTest.php
+++ b/core/modules/rest/src/Tests/Views/StyleSerializerTest.php
@@ -88,7 +88,7 @@ public function testRestViewsAuthentication() {
// to see the page.
$url = $this->buildUrl('test/serialize/auth_with_perm');
$response = \Drupal::httpClient()->get($url, [
- 'auth' => [$this->adminUser->getUsername(), $this->adminUser->pass_raw],
+ 'auth' => [$this->adminUser->getDisplayName(), $this->adminUser->pass_raw],
]);
// Ensure that any changes to variables in the other thread are picked up.
diff --git a/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php b/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php
index 191e0cf..7386399 100644
--- a/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php
+++ b/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php
@@ -136,7 +136,7 @@ public function testSearchModuleDisabling() {
'text' => $this->searchNode->label(),
],
'user_search' => [
- 'keys' => $this->searchUser->getUsername(),
+ 'keys' => $this->searchUser->getDisplayName(),
'text' => $this->searchUser->getEmail(),
],
'dummy_search_type' => [
diff --git a/core/modules/search/src/Tests/SearchPageCacheTagsTest.php b/core/modules/search/src/Tests/SearchPageCacheTagsTest.php
index 417d991..0372ae9 100644
--- a/core/modules/search/src/Tests/SearchPageCacheTagsTest.php
+++ b/core/modules/search/src/Tests/SearchPageCacheTagsTest.php
@@ -104,7 +104,7 @@ public function testSearchText() {
$this->assertNoCacheTag('search_index:user_search');
// User search results.
- $edit['keys'] = $this->searchingUser->getUsername();
+ $edit['keys'] = $this->searchingUser->getDisplayName();
$this->drupalPostForm('search/user', $edit, t('Search'));
$this->assertCacheTag('config:search.page.user_search');
$this->assertCacheTag('user_list');
diff --git a/core/modules/search/src/Tests/SearchPageTextTest.php b/core/modules/search/src/Tests/SearchPageTextTest.php
index 95d097d..008d16a 100644
--- a/core/modules/search/src/Tests/SearchPageTextTest.php
+++ b/core/modules/search/src/Tests/SearchPageTextTest.php
@@ -93,10 +93,10 @@ public function testSearchText() {
$actual_title = (string) current($this->xpath('//title'));
$this->assertEqual($actual_title, Html::decodeEntities(t($title_source, ['@keywords' => Unicode::truncate($search_terms, 60, TRUE, TRUE)])), 'Search page title is correct');
- $edit['keys'] = $this->searchingUser->getUsername();
+ $edit['keys'] = $this->searchingUser->getDisplayName();
$this->drupalPostForm('search/user', $edit, t('Search'));
$this->assertText(t('Search'));
- $this->assertTitle(t($title_source, ['@keywords' => Unicode::truncate($this->searchingUser->getUsername(), 60, TRUE, TRUE)]));
+ $this->assertTitle(t($title_source, ['@keywords' => Unicode::truncate($this->searchingUser->getDisplayName(), 60, TRUE, TRUE)]));
$this->clickLink('Search help');
$this->assertText('Search help', 'Correct title is on search help page');
diff --git a/core/modules/search/tests/src/Functional/SearchExactTest.php b/core/modules/search/tests/src/Functional/SearchExactTest.php
index 0416391..20f69e6 100644
--- a/core/modules/search/tests/src/Functional/SearchExactTest.php
+++ b/core/modules/search/tests/src/Functional/SearchExactTest.php
@@ -62,7 +62,7 @@ public function testExactQuery() {
$edit = ['keys' => 'Druplicon'];
$this->drupalPostForm('search/node', $edit, t('Search'));
- $this->assertText($user->getUsername(), 'Basic page node displays author name when post settings are on.');
+ $this->assertText($user->getDisplayName(), 'Basic page node displays author name when post settings are on.');
$this->assertText(format_date($node->getChangedTime(), 'short'), 'Basic page node displays post date when post settings are on.');
// Check that with post settings turned off the user and changed date
@@ -71,7 +71,7 @@ public function testExactQuery() {
$node_type_config->save();
$edit = ['keys' => 'Druplicon'];
$this->drupalPostForm('search/node', $edit, t('Search'));
- $this->assertNoText($user->getUsername(), 'Basic page node does not display author name when post settings are off.');
+ $this->assertNoText($user->getDisplayName(), 'Basic page node does not display author name when post settings are off.');
$this->assertNoText(format_date($node->getChangedTime(), 'short'), 'Basic page node does not display post date when post settings are off.');
}
diff --git a/core/modules/search/tests/src/Functional/SearchNodePunctuationTest.php b/core/modules/search/tests/src/Functional/SearchNodePunctuationTest.php
index 5935446..0d04fda 100644
--- a/core/modules/search/tests/src/Functional/SearchNodePunctuationTest.php
+++ b/core/modules/search/tests/src/Functional/SearchNodePunctuationTest.php
@@ -45,7 +45,7 @@ public function testPhraseSearchPunctuation() {
$this->assertText($node->label());
// Check if the author is linked correctly to the user profile page.
- $username = $node->getOwner()->getUsername();
+ $username = $node->getOwner()->getDisplayName();
$this->assertLink($username);
// Search for "&" and verify entities are not broken up in the output.
diff --git a/core/modules/serialization/tests/modules/entity_serialization_test/entity_serialization_test.module b/core/modules/serialization/tests/modules/entity_serialization_test/entity_serialization_test.module
index 26bd88c..ad5ac86 100644
--- a/core/modules/serialization/tests/modules/entity_serialization_test/entity_serialization_test.module
+++ b/core/modules/serialization/tests/modules/entity_serialization_test/entity_serialization_test.module
@@ -17,7 +17,7 @@
function entity_serialization_test_entity_field_access_alter(array &$grants, array $context) {
// Override default access control from UserAccessControlHandler to allow
// access to 'pass' field for the test user.
- if ($context['field_definition']->getName() == 'pass' && $context['account']->getUsername() == 'serialization_test_user') {
+ if ($context['field_definition']->getName() == 'pass' && $context['account']->getDisplayName() == 'serialization_test_user') {
$grants[':default'] = AccessResult::allowed()->inheritCacheability($grants[':default'])->addCacheableDependency($context['items']->getEntity());
}
}
diff --git a/core/modules/simpletest/src/Tests/BrowserTest.php b/core/modules/simpletest/src/Tests/BrowserTest.php
index fdfaff8..5554561 100644
--- a/core/modules/simpletest/src/Tests/BrowserTest.php
+++ b/core/modules/simpletest/src/Tests/BrowserTest.php
@@ -91,7 +91,7 @@ public function testXPathEscaping() {
public function testCookies() {
// Check that the $this->cookies property is populated when a user logs in.
$user = $this->drupalCreateUser();
- $edit = ['name' => $user->getUsername(), 'pass' => $user->pass_raw];
+ $edit = ['name' => $user->getDisplayName(), 'pass' => $user->pass_raw];
$this->drupalPostForm('', $edit, t('Log in'));
$this->assertEqual(count($this->cookies), 1, 'A cookie is set when the user logs in.');
diff --git a/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php b/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php
index 7e4f912..afcc2ef 100644
--- a/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php
+++ b/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php
@@ -58,7 +58,7 @@ public function testInternalBrowser() {
// Test the maximum redirection option.
$this->maximumRedirects = 1;
$edit = [
- 'name' => $user->getUsername(),
+ 'name' => $user->getDisplayName(),
'pass' => $user->pass_raw
];
$this->drupalPostForm('user/login', $edit, t('Log in'), [
diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php
index 2491bc8..11d8446 100644
--- a/core/modules/simpletest/src/WebTestBase.php
+++ b/core/modules/simpletest/src/WebTestBase.php
@@ -335,7 +335,7 @@ protected function drupalLogin(AccountInterface $account) {
}
$edit = [
- 'name' => $account->getUsername(),
+ 'name' => $account->getDisplayName(),
'pass' => $account->pass_raw
];
$this->drupalPostForm('user/login', $edit, t('Log in'));
@@ -344,7 +344,7 @@ protected function drupalLogin(AccountInterface $account) {
if (isset($this->sessionId)) {
$account->session_id = $this->sessionId;
}
- $pass = $this->assert($this->drupalUserIsLoggedIn($account), format_string('User %name successfully logged in.', ['%name' => $account->getUsername()]), 'User login');
+ $pass = $this->assert($this->drupalUserIsLoggedIn($account), format_string('User %name successfully logged in.', ['%name' => $account->getDisplayName()]), 'User login');
if ($pass) {
$this->loggedInUser = $account;
$this->container->get('current_user')->setAccount($account);
diff --git a/core/modules/system/src/Tests/Installer/DistributionProfileExistingSettingsTest.php b/core/modules/system/src/Tests/Installer/DistributionProfileExistingSettingsTest.php
index 2fe5d4f..3378e1d 100644
--- a/core/modules/system/src/Tests/Installer/DistributionProfileExistingSettingsTest.php
+++ b/core/modules/system/src/Tests/Installer/DistributionProfileExistingSettingsTest.php
@@ -117,7 +117,7 @@ public function testInstalled() {
$this->assertUrl('user/1');
$this->assertResponse(200);
// Confirm that we are logged-in after installation.
- $this->assertText($this->rootUser->getUsername());
+ $this->assertText($this->rootUser->getDisplayName());
// Confirm that Drupal recognizes this distribution as the current profile.
$this->assertEqual(\Drupal::installProfile(), 'mydistro');
diff --git a/core/modules/system/src/Tests/Installer/DistributionProfileTest.php b/core/modules/system/src/Tests/Installer/DistributionProfileTest.php
index e52b046..4c6e0aa 100644
--- a/core/modules/system/src/Tests/Installer/DistributionProfileTest.php
+++ b/core/modules/system/src/Tests/Installer/DistributionProfileTest.php
@@ -68,7 +68,7 @@ public function testInstalled() {
$this->assertUrl('user/1');
$this->assertResponse(200);
// Confirm that we are logged-in after installation.
- $this->assertText($this->rootUser->getUsername());
+ $this->assertText($this->rootUser->getDisplayName());
// Confirm that Drupal recognizes this distribution as the current profile.
$this->assertEqual(\Drupal::installProfile(), 'mydistro');
diff --git a/core/modules/system/src/Tests/Installer/InstallerTest.php b/core/modules/system/src/Tests/Installer/InstallerTest.php
index 01422a5..6a6e209 100644
--- a/core/modules/system/src/Tests/Installer/InstallerTest.php
+++ b/core/modules/system/src/Tests/Installer/InstallerTest.php
@@ -18,7 +18,7 @@ public function testInstaller() {
$this->assertUrl('user/1');
$this->assertResponse(200);
// Confirm that we are logged-in after installation.
- $this->assertText($this->rootUser->getUsername());
+ $this->assertText($this->rootUser->getDisplayName());
// Verify that the confirmation message appears.
require_once \Drupal::root() . '/core/includes/install.inc';
diff --git a/core/modules/system/src/Tests/Installer/MultipleDistributionsProfileTest.php b/core/modules/system/src/Tests/Installer/MultipleDistributionsProfileTest.php
index 171a0af..66e0a0e 100644
--- a/core/modules/system/src/Tests/Installer/MultipleDistributionsProfileTest.php
+++ b/core/modules/system/src/Tests/Installer/MultipleDistributionsProfileTest.php
@@ -76,7 +76,7 @@ public function testInstalled() {
$this->assertUrl('user/1');
$this->assertResponse(200);
// Confirm that we are logged-in after installation.
- $this->assertText($this->rootUser->getUsername());
+ $this->assertText($this->rootUser->getDisplayName());
// Confirm that Drupal recognizes this distribution as the current profile.
$this->assertEqual(\Drupal::installProfile(), 'distribution_one');
diff --git a/core/modules/system/src/Tests/Installer/SingleVisibleProfileTest.php b/core/modules/system/src/Tests/Installer/SingleVisibleProfileTest.php
index 91af34a..c46c190 100644
--- a/core/modules/system/src/Tests/Installer/SingleVisibleProfileTest.php
+++ b/core/modules/system/src/Tests/Installer/SingleVisibleProfileTest.php
@@ -57,7 +57,7 @@ public function testInstalled() {
$this->assertUrl('user/1');
$this->assertResponse(200);
// Confirm that we are logged-in after installation.
- $this->assertText($this->rootUser->getUsername());
+ $this->assertText($this->rootUser->getDisplayName());
// Confirm that the minimal profile was installed.
$this->assertEqual(drupal_get_profile(), 'minimal');
}
diff --git a/core/modules/system/src/Tests/Menu/BreadcrumbTest.php b/core/modules/system/src/Tests/Menu/BreadcrumbTest.php
index 64c8c15..6f7e509 100644
--- a/core/modules/system/src/Tests/Menu/BreadcrumbTest.php
+++ b/core/modules/system/src/Tests/Menu/BreadcrumbTest.php
@@ -311,17 +311,17 @@ public function testBreadCrumbs() {
// Verify breadcrumb on user pages (without menu link) for anonymous user.
$trail = $home;
$this->assertBreadcrumb('user', $trail, t('Log in'));
- $this->assertBreadcrumb('user/' . $this->adminUser->id(), $trail, $this->adminUser->getUsername());
+ $this->assertBreadcrumb('user/' . $this->adminUser->id(), $trail, $this->adminUser->getDisplayName());
// Verify breadcrumb on user pages (without menu link) for registered users.
$this->drupalLogin($this->adminUser);
$trail = $home;
- $this->assertBreadcrumb('user', $trail, $this->adminUser->getUsername());
- $this->assertBreadcrumb('user/' . $this->adminUser->id(), $trail, $this->adminUser->getUsername());
+ $this->assertBreadcrumb('user', $trail, $this->adminUser->getDisplayName());
+ $this->assertBreadcrumb('user/' . $this->adminUser->id(), $trail, $this->adminUser->getDisplayName());
$trail += [
- 'user/' . $this->adminUser->id() => $this->adminUser->getUsername(),
+ 'user/' . $this->adminUser->id() => $this->adminUser->getDisplayName(),
];
- $this->assertBreadcrumb('user/' . $this->adminUser->id() . '/edit', $trail, $this->adminUser->getUsername());
+ $this->assertBreadcrumb('user/' . $this->adminUser->id() . '/edit', $trail, $this->adminUser->getDisplayName());
// Create a second user to verify breadcrumb on user pages again.
$this->webUser = $this->drupalCreateUser([
@@ -332,19 +332,19 @@ public function testBreadCrumbs() {
// Verify correct breadcrumb and page title on another user's account pages.
$trail = $home;
- $this->assertBreadcrumb('user/' . $this->adminUser->id(), $trail, $this->adminUser->getUsername());
+ $this->assertBreadcrumb('user/' . $this->adminUser->id(), $trail, $this->adminUser->getDisplayName());
$trail += [
- 'user/' . $this->adminUser->id() => $this->adminUser->getUsername(),
+ 'user/' . $this->adminUser->id() => $this->adminUser->getDisplayName(),
];
- $this->assertBreadcrumb('user/' . $this->adminUser->id() . '/edit', $trail, $this->adminUser->getUsername());
+ $this->assertBreadcrumb('user/' . $this->adminUser->id() . '/edit', $trail, $this->adminUser->getDisplayName());
// Verify correct breadcrumb and page title when viewing own user account.
$trail = $home;
- $this->assertBreadcrumb('user/' . $this->webUser->id(), $trail, $this->webUser->getUsername());
+ $this->assertBreadcrumb('user/' . $this->webUser->id(), $trail, $this->webUser->getDisplayName());
$trail += [
- 'user/' . $this->webUser->id() => $this->webUser->getUsername(),
+ 'user/' . $this->webUser->id() => $this->webUser->getDisplayName(),
];
- $this->assertBreadcrumb('user/' . $this->webUser->id() . '/edit', $trail, $this->webUser->getUsername());
+ $this->assertBreadcrumb('user/' . $this->webUser->id() . '/edit', $trail, $this->webUser->getDisplayName());
// Create an only slightly privileged user being able to access site reports
// but not administration pages.
diff --git a/core/modules/system/src/Tests/Routing/RouterTest.php b/core/modules/system/src/Tests/Routing/RouterTest.php
index 38d7ecb..9d2d89d 100644
--- a/core/modules/system/src/Tests/Routing/RouterTest.php
+++ b/core/modules/system/src/Tests/Routing/RouterTest.php
@@ -264,11 +264,11 @@ public function testUserAccount() {
$second_account = $this->drupalCreateUser();
$this->drupalGet('router_test/test12/' . $second_account->id());
- $this->assertText($account->getUsername() . ':' . $second_account->getUsername());
+ $this->assertText($account->getDisplayName() . ':' . $second_account->getDisplayName());
$this->assertEqual($account->id(), $this->loggedInUser->id(), 'Ensure that the user was not changed.');
$this->drupalGet('router_test/test13/' . $second_account->id());
- $this->assertText($account->getUsername() . ':' . $second_account->getUsername());
+ $this->assertText($account->getDisplayName() . ':' . $second_account->getDisplayName());
$this->assertEqual($account->id(), $this->loggedInUser->id(), 'Ensure that the user was not changed.');
}
diff --git a/core/modules/system/src/Tests/Session/SessionAuthenticationTest.php b/core/modules/system/src/Tests/Session/SessionAuthenticationTest.php
index ffdc08d..c0bdc2c 100644
--- a/core/modules/system/src/Tests/Session/SessionAuthenticationTest.php
+++ b/core/modules/system/src/Tests/Session/SessionAuthenticationTest.php
@@ -55,7 +55,7 @@ public function testSessionFromBasicAuthenticationDoesNotLeak() {
$this->assertResponse(401, 'An anonymous user cannot access a route protected with basic authentication.');
// We should be able to access the route with basic authentication.
- $this->basicAuthGet($protected_url, $this->user->getUsername(), $this->user->pass_raw);
+ $this->basicAuthGet($protected_url, $this->user->getDisplayName(), $this->user->pass_raw);
$this->assertResponse(200, 'A route protected with basic authentication can be accessed by an authenticated user.');
// Check that the correct user is logged in.
@@ -79,12 +79,12 @@ public function testSessionFromBasicAuthenticationDoesNotLeak() {
public function testBasicAuthSession() {
// Set a session value on a request through basic auth.
$test_value = 'alpaca';
- $response = $this->basicAuthGet('session-test/set-session/' . $test_value, $this->user->getUsername(), $this->user->pass_raw);
+ $response = $this->basicAuthGet('session-test/set-session/' . $test_value, $this->user->getDisplayName(), $this->user->pass_raw);
$this->assertSessionData($response, $test_value);
$this->assertResponse(200, 'The request to set a session value was successful.');
// Test that on a subsequent request the session value is still present.
- $response = $this->basicAuthGet('session-test/get-session', $this->user->getUsername(), $this->user->pass_raw);
+ $response = $this->basicAuthGet('session-test/get-session', $this->user->getDisplayName(), $this->user->pass_raw);
$this->assertSessionData($response, $test_value);
$this->assertResponse(200, 'The request to get a session value was successful.');
}
@@ -118,12 +118,12 @@ public function testBasicAuthNoSession() {
// If we authenticate with a third party authentication system then no
// session cookie should be set, the third party system is responsible for
// sustaining the session.
- $this->basicAuthGet($no_cookie_url, $this->user->getUsername(), $this->user->pass_raw);
+ $this->basicAuthGet($no_cookie_url, $this->user->getDisplayName(), $this->user->pass_raw);
$this->assertResponse(200, 'The user is successfully authenticated using basic authentication.');
$this->assertFalse($this->drupalGetHeader('set-cookie', TRUE), 'No cookie is set on a route protected with basic authentication.');
// On the other hand, authenticating using Cookie sets a cookie.
- $edit = ['name' => $this->user->getUsername(), 'pass' => $this->user->pass_raw];
+ $edit = ['name' => $this->user->getDisplayName(), 'pass' => $this->user->pass_raw];
$this->drupalPostForm($cookie_url, $edit, t('Log in'));
$this->assertResponse(200, 'The user is successfully authenticated using cookie authentication.');
$this->assertTrue($this->drupalGetHeader('set-cookie', TRUE), 'A cookie is set on a route protected with cookie authentication.');
diff --git a/core/modules/system/src/Tests/Session/SessionHttpsTest.php b/core/modules/system/src/Tests/Session/SessionHttpsTest.php
index 6ba70da..3d54364 100644
--- a/core/modules/system/src/Tests/Session/SessionHttpsTest.php
+++ b/core/modules/system/src/Tests/Session/SessionHttpsTest.php
@@ -117,7 +117,7 @@ protected function loginHttp(AccountInterface $account) {
// creates a mock HTTP request on HTTPS test environments.
$form = $this->xpath('//form[@id="user-login-form"]');
$form[0]['action'] = $this->httpUrl('user/login');
- $edit = ['name' => $account->getUsername(), 'pass' => $account->pass_raw];
+ $edit = ['name' => $account->getDisplayName(), 'pass' => $account->pass_raw];
// When posting directly to the HTTP or HTTPS mock front controller, the
// location header on the returned response is an absolute URL. That URL
@@ -148,7 +148,7 @@ protected function loginHttps(AccountInterface $account) {
// creates a mock HTTPS request on HTTP test environments.
$form = $this->xpath('//form[@id="user-login-form"]');
$form[0]['action'] = $this->httpsUrl('user/login');
- $edit = ['name' => $account->getUsername(), 'pass' => $account->pass_raw];
+ $edit = ['name' => $account->getDisplayName(), 'pass' => $account->pass_raw];
// When posting directly to the HTTP or HTTPS mock front controller, the
// location header on the returned response is an absolute URL. That URL
diff --git a/core/modules/system/src/Tests/Session/SessionTest.php b/core/modules/system/src/Tests/Session/SessionTest.php
index fcadd42..0c2fb66 100644
--- a/core/modules/system/src/Tests/Session/SessionTest.php
+++ b/core/modules/system/src/Tests/Session/SessionTest.php
@@ -56,12 +56,12 @@ public function testSessionSaveRegenerate() {
// We cannot use $this->drupalLogin($user); because we exit in
// session_test_user_login() which breaks a normal assertion.
$edit = [
- 'name' => $user->getUsername(),
+ 'name' => $user->getDisplayName(),
'pass' => $user->pass_raw
];
$this->drupalPostForm('user/login', $edit, t('Log in'));
$this->drupalGet('user');
- $pass = $this->assertText($user->getUsername(), format_string('Found name: %name', ['%name' => $user->getUsername()]), 'User login');
+ $pass = $this->assertText($user->getDisplayName(), format_string('Found name: %name', ['%name' => $user->getDisplayName()]), 'User login');
$this->_logged_in = $pass;
$this->drupalGet('session-test/id');
diff --git a/core/modules/system/src/Tests/System/AccessDeniedTest.php b/core/modules/system/src/Tests/System/AccessDeniedTest.php
index ba1d599..0e56a54 100644
--- a/core/modules/system/src/Tests/System/AccessDeniedTest.php
+++ b/core/modules/system/src/Tests/System/AccessDeniedTest.php
@@ -70,7 +70,7 @@ public function testAccessDenied() {
// Log out and check that the user login block is shown on custom 403 pages.
$this->drupalLogout();
$this->drupalGet('admin');
- $this->assertText($this->adminUser->getUsername(), 'Found the custom 403 page');
+ $this->assertText($this->adminUser->getDisplayName(), 'Found the custom 403 page');
$this->assertText(t('Username'), 'Blocks are shown on the custom 403 page');
// Log back in and remove the custom 403 page.
@@ -95,7 +95,7 @@ public function testAccessDenied() {
// Check that we can log in from the 403 page.
$this->drupalLogout();
$edit = [
- 'name' => $this->adminUser->getUsername(),
+ 'name' => $this->adminUser->getDisplayName(),
'pass' => $this->adminUser->pass_raw,
];
$this->drupalPostForm('admin/config/system/site-information', $edit, t('Log in'));
diff --git a/core/modules/system/src/Tests/System/PageNotFoundTest.php b/core/modules/system/src/Tests/System/PageNotFoundTest.php
index b1a88d8..3659d9f 100644
--- a/core/modules/system/src/Tests/System/PageNotFoundTest.php
+++ b/core/modules/system/src/Tests/System/PageNotFoundTest.php
@@ -53,7 +53,7 @@ public function testPageNotFound() {
$this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
$this->drupalGet($this->randomMachineName(10));
- $this->assertText($this->adminUser->getUsername(), 'Found the custom 404 page');
+ $this->assertText($this->adminUser->getDisplayName(), 'Found the custom 404 page');
}
/**
diff --git a/core/modules/system/src/Tests/System/SiteMaintenanceTest.php b/core/modules/system/src/Tests/System/SiteMaintenanceTest.php
index e269a6c..5b42b08 100644
--- a/core/modules/system/src/Tests/System/SiteMaintenanceTest.php
+++ b/core/modules/system/src/Tests/System/SiteMaintenanceTest.php
@@ -89,7 +89,7 @@ public function testSiteMaintenance() {
// Log in user and verify that maintenance mode message is displayed
// directly after login.
$edit = [
- 'name' => $this->user->getUsername(),
+ 'name' => $this->user->getDisplayName(),
'pass' => $this->user->pass_raw,
];
$this->drupalPostForm(NULL, $edit, t('Log in'));
@@ -119,7 +119,7 @@ public function testSiteMaintenance() {
// Submit password reset form.
$edit = [
- 'name' => $this->user->getUsername(),
+ 'name' => $this->user->getDisplayName(),
];
$this->drupalPostForm('user/password', $edit, t('Submit'));
$mails = $this->drupalGetMails();
diff --git a/core/modules/system/src/Tests/Update/UpdatePathTestBase.php b/core/modules/system/src/Tests/Update/UpdatePathTestBase.php
index f7f88c6..e2f14f8 100644
--- a/core/modules/system/src/Tests/Update/UpdatePathTestBase.php
+++ b/core/modules/system/src/Tests/Update/UpdatePathTestBase.php
@@ -335,7 +335,7 @@ protected function replaceUser1() {
$account = User::load(1);
$account->setPassword($this->rootUser->pass_raw);
$account->setEmail($this->rootUser->getEmail());
- $account->setUsername($this->rootUser->getUsername());
+ $account->setUsername($this->rootUser->getDisplayName());
$account->save();
}
diff --git a/core/modules/system/tests/modules/database_test/src/Form/DatabaseTestForm.php b/core/modules/system/tests/modules/database_test/src/Form/DatabaseTestForm.php
index 12eebcc..46bbcfd 100644
--- a/core/modules/system/tests/modules/database_test/src/Form/DatabaseTestForm.php
+++ b/core/modules/system/tests/modules/database_test/src/Form/DatabaseTestForm.php
@@ -50,8 +50,8 @@ public function buildForm(array $form, FormStateInterface $form_state) {
foreach (User::loadMultiple($uids) as $account) {
$options[$account->id()] = [
- 'title' => ['data' => ['#title' => $account->getUsername()]],
- 'username' => $account->getUsername(),
+ 'title' => ['data' => ['#title' => $account->getDisplayName()]],
+ 'username' => $account->getDisplayName(),
'status' => $account->isActive() ? t('active') : t('blocked'),
];
}
diff --git a/core/modules/system/tests/modules/form_test/src/Controller/FormTestController.php b/core/modules/system/tests/modules/form_test/src/Controller/FormTestController.php
index 4c9fbe2..d613a59 100644
--- a/core/modules/system/tests/modules/form_test/src/Controller/FormTestController.php
+++ b/core/modules/system/tests/modules/form_test/src/Controller/FormTestController.php
@@ -22,7 +22,7 @@ public function twoFormInstances() {
$user = $this->currentUser();
$values = [
'uid' => $user->id(),
- 'name' => $user->getUsername(),
+ 'name' => $user->getDisplayName(),
'type' => 'page',
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
];
diff --git a/core/modules/system/tests/modules/router_test_directory/src/TestContent.php b/core/modules/system/tests/modules/router_test_directory/src/TestContent.php
index f392a81..ad60f1c 100644
--- a/core/modules/system/tests/modules/router_test_directory/src/TestContent.php
+++ b/core/modules/system/tests/modules/router_test_directory/src/TestContent.php
@@ -49,13 +49,13 @@ public function test1() {
*/
public function test11() {
$account = $this->currentUser();
- return ['#markup' => $account->getUsername()];
+ return ['#markup' => $account->getDisplayName()];
}
public function testAccount(UserInterface $user) {
- $current_user_name = $this->currentUser()->getUsername();
+ $current_user_name = $this->currentUser()->getDisplayName();
$this->currentUser()->setAccount($user);
- return ['#markup' => $current_user_name . ':' . $user->getUsername()];
+ return ['#markup' => $current_user_name . ':' . $user->getDisplayName()];
}
/**
diff --git a/core/modules/system/tests/modules/session_test/session_test.module b/core/modules/system/tests/modules/session_test/session_test.module
index b3ceff8..9da3337 100644
--- a/core/modules/system/tests/modules/session_test/session_test.module
+++ b/core/modules/system/tests/modules/session_test/session_test.module
@@ -9,7 +9,7 @@
* Implements hook_user_login().
*/
function session_test_user_login($account) {
- if ($account->getUsername() == 'session_test_user') {
+ if ($account->getDisplayName() == 'session_test_user') {
// Exit so we can verify that the session was regenerated
// before hook_user_login() was called.
exit;
diff --git a/core/modules/system/tests/modules/url_alter_test/src/PathProcessorTest.php b/core/modules/system/tests/modules/url_alter_test/src/PathProcessorTest.php
index 9a89df9..a0bde5a 100644
--- a/core/modules/system/tests/modules/url_alter_test/src/PathProcessorTest.php
+++ b/core/modules/system/tests/modules/url_alter_test/src/PathProcessorTest.php
@@ -42,7 +42,7 @@ public function processOutbound($path, &$options = [], Request $request = NULL,
if (preg_match('!^/user/([0-9]+)(/.*)?!', $path, $matches)) {
if ($account = User::load($matches[1])) {
$matches += [2 => ''];
- $path = '/user/' . $account->getUsername() . $matches[2];
+ $path = '/user/' . $account->getDisplayName() . $matches[2];
if ($bubbleable_metadata) {
$bubbleable_metadata->addCacheTags($account->getCacheTags());
}
diff --git a/core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php b/core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
index df33102..fa49015 100644
--- a/core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
+++ b/core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
@@ -239,7 +239,7 @@ public function testUserHandler() {
$account = $values;
}
$users[$key] = $account;
- $user_labels[$key] = Html::escape($account->getUsername());
+ $user_labels[$key] = Html::escape($account->getDisplayName());
}
// Test as a non-admin.
diff --git a/core/modules/system/tests/src/Functional/Path/UrlAlterFunctionalTest.php b/core/modules/system/tests/src/Functional/Path/UrlAlterFunctionalTest.php
index 2717741..e2672ae 100644
--- a/core/modules/system/tests/src/Functional/Path/UrlAlterFunctionalTest.php
+++ b/core/modules/system/tests/src/Functional/Path/UrlAlterFunctionalTest.php
@@ -34,7 +34,7 @@ public function testUrlAlter() {
$this->drupalLogin($account);
$uid = $account->id();
- $name = $account->getUsername();
+ $name = $account->getDisplayName();
// Test a single altered path.
$this->drupalGet("user/$name");
diff --git a/core/modules/system/tests/src/Functional/Theme/FastTest.php b/core/modules/system/tests/src/Functional/Theme/FastTest.php
index d8f85f1..f499e3a 100644
--- a/core/modules/system/tests/src/Functional/Theme/FastTest.php
+++ b/core/modules/system/tests/src/Functional/Theme/FastTest.php
@@ -28,8 +28,8 @@ protected function setUp() {
*/
public function testUserAutocomplete() {
$this->drupalLogin($this->account);
- $this->drupalGet('user/autocomplete', ['query' => ['q' => $this->account->getUsername()]]);
- $this->assertRaw($this->account->getUsername());
+ $this->drupalGet('user/autocomplete', ['query' => ['q' => $this->account->getDisplayName()]]);
+ $this->assertRaw($this->account->getDisplayName());
$this->assertNoText('registry initialized', 'The registry was not initialized');
}
diff --git a/core/modules/tracker/src/Controller/TrackerUserTab.php b/core/modules/tracker/src/Controller/TrackerUserTab.php
index d9c774d..24cf16b 100644
--- a/core/modules/tracker/src/Controller/TrackerUserTab.php
+++ b/core/modules/tracker/src/Controller/TrackerUserTab.php
@@ -22,7 +22,7 @@ public function getContent(UserInterface $user) {
* Title callback for the tracker.user_tab route.
*/
public function getTitle(UserInterface $user) {
- return $user->getUsername();
+ return $user->getDisplayName();
}
}
diff --git a/core/modules/tracker/tests/src/Functional/TrackerTest.php b/core/modules/tracker/tests/src/Functional/TrackerTest.php
index 17f95ee..93271e8 100644
--- a/core/modules/tracker/tests/src/Functional/TrackerTest.php
+++ b/core/modules/tracker/tests/src/Functional/TrackerTest.php
@@ -197,7 +197,7 @@ public function testTrackerUser() {
$this->assertNoLink($unpublished->label());
// Verify that title and tab title have been set correctly.
$this->assertText('Activity', 'The user activity tab has the name "Activity".');
- $this->assertTitle(t('@name | @site', ['@name' => $this->user->getUsername(), '@site' => $this->config('system.site')->get('name')]), 'The user tracker page has the correct page title.');
+ $this->assertTitle(t('@name | @site', ['@name' => $this->user->getDisplayName(), '@site' => $this->config('system.site')->get('name')]), 'The user tracker page has the correct page title.');
// Verify that unpublished comments are removed from the tracker.
$admin_user = $this->drupalCreateUser(['post comments', 'administer comments', 'access user profiles']);
diff --git a/core/modules/user/src/Controller/UserController.php b/core/modules/user/src/Controller/UserController.php
index be15fac..97f9fec 100644
--- a/core/modules/user/src/Controller/UserController.php
+++ b/core/modules/user/src/Controller/UserController.php
@@ -121,7 +121,7 @@ public function resetPass(Request $request, $uid, $timestamp, $hash) {
/** @var \Drupal\user\UserInterface $reset_link_user */
if ($reset_link_user = $this->userStorage->load($uid)) {
drupal_set_message($this->t('Another user (%other_user) is already logged into the site on this computer, but you tried to use a one-time link for user %resetting_user. Please log out and try using the link again.',
- ['%other_user' => $account->getUsername(), '%resetting_user' => $reset_link_user->getUsername(), ':logout' => $this->url('user.logout')]), 'warning');
+ ['%other_user' => $account->getDisplayName(), '%resetting_user' => $reset_link_user->getDisplayName(), ':logout' => $this->url('user.logout')]), 'warning');
}
else {
// Invalid one-time link specifies an unknown user.
@@ -268,7 +268,7 @@ public function userPage() {
* NULL.
*/
public function userTitle(UserInterface $user = NULL) {
- return $user ? ['#markup' => $user->getUsername(), '#allowed_tags' => Xss::getHtmlTagList()] : '';
+ return $user ? ['#markup' => $user->getDisplayName(), '#allowed_tags' => Xss::getHtmlTagList()] : '';
}
/**
diff --git a/core/modules/user/src/Form/UserPasswordForm.php b/core/modules/user/src/Form/UserPasswordForm.php
index ea224fe..98bd1cf 100644
--- a/core/modules/user/src/Form/UserPasswordForm.php
+++ b/core/modules/user/src/Form/UserPasswordForm.php
@@ -140,7 +140,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
// Mail one time login URL and instructions using current language.
$mail = _user_mail_notify('password_reset', $account, $langcode);
if (!empty($mail)) {
- $this->logger('user')->notice('Password reset instructions mailed to %name at %email.', ['%name' => $account->getUsername(), '%email' => $account->getEmail()]);
+ $this->logger('user')->notice('Password reset instructions mailed to %name at %email.', ['%name' => $account->getDisplayName(), '%email' => $account->getEmail()]);
drupal_set_message($this->t('Further instructions have been sent to your email address.'));
}
diff --git a/core/modules/user/src/Form/UserPasswordResetForm.php b/core/modules/user/src/Form/UserPasswordResetForm.php
index ce8c7cc..79f90bb 100644
--- a/core/modules/user/src/Form/UserPasswordResetForm.php
+++ b/core/modules/user/src/Form/UserPasswordResetForm.php
@@ -38,12 +38,12 @@ public function getFormId() {
*/
public function buildForm(array $form, FormStateInterface $form_state, AccountInterface $user = NULL, $expiration_date = NULL, $timestamp = NULL, $hash = NULL) {
if ($expiration_date) {
- $form['message'] = ['#markup' => $this->t('This is a one-time login for %user_name and will expire on %expiration_date.
Click on this button to log in to the site and change your password.
', ['%user_name' => $user->getUsername(), '%expiration_date' => $expiration_date])];
+ $form['message'] = ['#markup' => $this->t('This is a one-time login for %user_name and will expire on %expiration_date.
Click on this button to log in to the site and change your password.
', ['%user_name' => $user->getDisplayName(), '%expiration_date' => $expiration_date])];
$form['#title'] = $this->t('Reset password');
}
else {
// No expiration for first time login.
- $form['message'] = ['#markup' => $this->t('This is a one-time login for %user_name.
Click on this button to log in to the site and change your password.
', ['%user_name' => $user->getUsername()])];
+ $form['message'] = ['#markup' => $this->t('This is a one-time login for %user_name.
Click on this button to log in to the site and change your password.
', ['%user_name' => $user->getDisplayName()])];
$form['#title'] = $this->t('Set password');
}
diff --git a/core/modules/user/src/Plugin/views/argument_validator/UserName.php b/core/modules/user/src/Plugin/views/argument_validator/UserName.php
index 8ef4999..268b12c 100644
--- a/core/modules/user/src/Plugin/views/argument_validator/UserName.php
+++ b/core/modules/user/src/Plugin/views/argument_validator/UserName.php
@@ -56,7 +56,7 @@ public function validateArgument($argument) {
// Validate each account. If any fails break out and return false.
foreach ($accounts as $account) {
- if (!in_array($account->getUserName(), $names) || !$this->validateEntity($account)) {
+ if (!in_array($account->getDisplayName(), $names) || !$this->validateEntity($account)) {
return FALSE;
}
}
diff --git a/core/modules/user/src/RegisterForm.php b/core/modules/user/src/RegisterForm.php
index 7a97974..07766d8 100644
--- a/core/modules/user/src/RegisterForm.php
+++ b/core/modules/user/src/RegisterForm.php
@@ -101,7 +101,7 @@ public function save(array $form, FormStateInterface $form_state) {
// New administrative account without notification.
if ($admin && !$notify) {
- drupal_set_message($this->t('Created a new user account for %name. No email has been sent.', [':url' => $account->url(), '%name' => $account->getUsername()]));
+ drupal_set_message($this->t('Created a new user account for %name. No email has been sent.', [':url' => $account->url(), '%name' => $account->getDisplayName()]));
}
// No email verification required; log in user immediately.
elseif (!$admin && !\Drupal::config('user.settings')->get('verify_mail') && $account->isActive()) {
@@ -113,13 +113,13 @@ public function save(array $form, FormStateInterface $form_state) {
// No administrator approval required.
elseif ($account->isActive() || $notify) {
if (!$account->getEmail() && $notify) {
- drupal_set_message($this->t('The new user %name was created without an email address, so no welcome message was sent.', [':url' => $account->url(), '%name' => $account->getUsername()]));
+ drupal_set_message($this->t('The new user %name was created without an email address, so no welcome message was sent.', [':url' => $account->url(), '%name' => $account->getDisplayName()]));
}
else {
$op = $notify ? 'register_admin_created' : 'register_no_approval_required';
if (_user_mail_notify($op, $account)) {
if ($notify) {
- drupal_set_message($this->t('A welcome message with further instructions has been emailed to the new user %name.', [':url' => $account->url(), '%name' => $account->getUsername()]));
+ drupal_set_message($this->t('A welcome message with further instructions has been emailed to the new user %name.', [':url' => $account->url(), '%name' => $account->getDisplayName()]));
}
else {
drupal_set_message($this->t('A welcome message with further instructions has been sent to your email address.'));
diff --git a/core/modules/user/src/Tests/UserAdminTest.php b/core/modules/user/src/Tests/UserAdminTest.php
index f3ee85a..720610d 100644
--- a/core/modules/user/src/Tests/UserAdminTest.php
+++ b/core/modules/user/src/Tests/UserAdminTest.php
@@ -45,10 +45,10 @@ public function testUserAdmin() {
$admin_user->save();
$this->drupalLogin($admin_user);
$this->drupalGet('admin/people');
- $this->assertText($user_a->getUsername(), 'Found user A on admin users page');
- $this->assertText($user_b->getUsername(), 'Found user B on admin users page');
- $this->assertText($user_c->getUsername(), 'Found user C on admin users page');
- $this->assertText($admin_user->getUsername(), 'Found Admin user on admin users page');
+ $this->assertText($user_a->getDisplayName(), 'Found user A on admin users page');
+ $this->assertText($user_b->getDisplayName(), 'Found user B on admin users page');
+ $this->assertText($user_c->getDisplayName(), 'Found user C on admin users page');
+ $this->assertText($admin_user->getDisplayName(), 'Found Admin user on admin users page');
// Test for existence of edit link in table.
$link = $user_a->link(t('Edit'), 'edit-form', ['query' => ['destination' => $user_a->url('collection')]]);
@@ -63,23 +63,23 @@ public function testUserAdmin() {
$this->assertNoField('edit-reduce-duplicates', 'Reduce duplicates form element not found in exposed filters.');
// Filter the users by name/email.
- $this->drupalGet('admin/people', ['query' => ['user' => $user_a->getUsername()]]);
+ $this->drupalGet('admin/people', ['query' => ['user' => $user_a->getDisplayName()]]);
$result = $this->xpath('//table/tbody/tr');
$this->assertEqual(1, count($result), 'Filter by username returned the right amount.');
- $this->assertEqual($user_a->getUsername(), (string) $result[0]->td[1]->span, 'Filter by username returned the right user.');
+ $this->assertEqual($user_a->getDisplayName(), (string) $result[0]->td[1]->span, 'Filter by username returned the right user.');
$this->drupalGet('admin/people', ['query' => ['user' => $user_a->getEmail()]]);
$result = $this->xpath('//table/tbody/tr');
$this->assertEqual(1, count($result), 'Filter by username returned the right amount.');
- $this->assertEqual($user_a->getUsername(), (string) $result[0]->td[1]->span, 'Filter by username returned the right user.');
+ $this->assertEqual($user_a->getDisplayName(), (string) $result[0]->td[1]->span, 'Filter by username returned the right user.');
// Filter the users by permission 'administer taxonomy'.
$this->drupalGet('admin/people', ['query' => ['permission' => 'administer taxonomy']]);
// Check if the correct users show up.
- $this->assertNoText($user_a->getUsername(), 'User A not on filtered by perm admin users page');
- $this->assertText($user_b->getUsername(), 'Found user B on filtered by perm admin users page');
- $this->assertText($user_c->getUsername(), 'Found user C on filtered by perm admin users page');
+ $this->assertNoText($user_a->getDisplayName(), 'User A not on filtered by perm admin users page');
+ $this->assertText($user_b->getDisplayName(), 'Found user B on filtered by perm admin users page');
+ $this->assertText($user_c->getDisplayName(), 'Found user C on filtered by perm admin users page');
// Filter the users by role. Grab the system-generated role name for User C.
$roles = $user_c->getRoles();
@@ -87,9 +87,9 @@ public function testUserAdmin() {
$this->drupalGet('admin/people', ['query' => ['role' => reset($roles)]]);
// Check if the correct users show up when filtered by role.
- $this->assertNoText($user_a->getUsername(), 'User A not on filtered by role on admin users page');
- $this->assertNoText($user_b->getUsername(), 'User B not on filtered by role on admin users page');
- $this->assertText($user_c->getUsername(), 'User C on filtered by role on admin users page');
+ $this->assertNoText($user_a->getDisplayName(), 'User A not on filtered by role on admin users page');
+ $this->assertNoText($user_b->getDisplayName(), 'User B not on filtered by role on admin users page');
+ $this->assertText($user_c->getDisplayName(), 'User C on filtered by role on admin users page');
// Test blocking of a user.
$account = $user_storage->load($user_c->id());
@@ -113,9 +113,9 @@ public function testUserAdmin() {
// Test filtering on admin page for blocked users
$this->drupalGet('admin/people', ['query' => ['status' => 2]]);
- $this->assertNoText($user_a->getUsername(), 'User A not on filtered by status on admin users page');
- $this->assertNoText($user_b->getUsername(), 'User B not on filtered by status on admin users page');
- $this->assertText($user_c->getUsername(), 'User C on filtered by status on admin users page');
+ $this->assertNoText($user_a->getDisplayName(), 'User A not on filtered by status on admin users page');
+ $this->assertNoText($user_b->getDisplayName(), 'User B not on filtered by status on admin users page');
+ $this->assertText($user_c->getDisplayName(), 'User C on filtered by status on admin users page');
// Test unblocking of a user from /admin/people page and sending of activation mail
$editunblock = [];
diff --git a/core/modules/user/src/Tests/UserBlocksTest.php b/core/modules/user/src/Tests/UserBlocksTest.php
index 0a4c619..b9c21e4 100644
--- a/core/modules/user/src/Tests/UserBlocksTest.php
+++ b/core/modules/user/src/Tests/UserBlocksTest.php
@@ -68,7 +68,7 @@ public function testUserLoginBlock() {
// Log in using the block.
$edit = [];
- $edit['name'] = $user->getUsername();
+ $edit['name'] = $user->getDisplayName();
$edit['pass'] = $user->pass_raw;
$this->drupalPostForm('admin/people/permissions', $edit, t('Log in'));
$this->assertNoText(t('User login'), 'Logged in.');
@@ -147,10 +147,10 @@ public function testWhosOnlineBlock() {
$content = entity_view($block, 'block');
$this->setRawContent(\Drupal::service('renderer')->renderRoot($content));
$this->assertRaw(t('2 users'), 'Correct number of online users (2 users).');
- $this->assertText($user1->getUsername(), 'Active user 1 found in online list.');
- $this->assertText($user2->getUsername(), 'Active user 2 found in online list.');
- $this->assertNoText($user3->getUsername(), 'Inactive user not found in online list.');
- $this->assertTrue(strpos($this->getRawContent(), $user1->getUsername()) > strpos($this->getRawContent(), $user2->getUsername()), 'Online users are ordered correctly.');
+ $this->assertText($user1->getDisplayName(), 'Active user 1 found in online list.');
+ $this->assertText($user2->getDisplayName(), 'Active user 2 found in online list.');
+ $this->assertNoText($user3->getDisplayName(), 'Inactive user not found in online list.');
+ $this->assertTrue(strpos($this->getRawContent(), $user1->getDisplayName()) > strpos($this->getRawContent(), $user2->getDisplayName()), 'Online users are ordered correctly.');
}
/**
diff --git a/core/modules/user/src/Tests/UserCancelTest.php b/core/modules/user/src/Tests/UserCancelTest.php
index a74626e..70363a9 100644
--- a/core/modules/user/src/Tests/UserCancelTest.php
+++ b/core/modules/user/src/Tests/UserCancelTest.php
@@ -84,7 +84,7 @@ public function testUserCancelChangePermission() {
$this->drupalPostForm('user_form_test_cancel/' . $account->id(), [], t('Cancel account'));
// Confirm deletion.
- $this->assertRaw(t('%name has been deleted.', ['%name' => $account->getUsername()]), 'User deleted.');
+ $this->assertRaw(t('%name has been deleted.', ['%name' => $account->getDisplayName()]), 'User deleted.');
$this->assertFalse(User::load($account->id()), 'User is not found in the database.');
}
@@ -215,7 +215,7 @@ public function testUserBlock() {
$this->assertTrue($account->isBlocked(), 'User has been blocked.');
// Confirm that the confirmation message made it through to the end user.
- $this->assertRaw(t('%name has been disabled.', ['%name' => $account->getUsername()]), "Confirmation message displayed to user.");
+ $this->assertRaw(t('%name has been disabled.', ['%name' => $account->getDisplayName()]), "Confirmation message displayed to user.");
}
/**
@@ -285,7 +285,7 @@ public function testUserBlockUnpublish() {
$this->assertFalse($comment->isPublished(), 'Comment of the user has been unpublished.');
// Confirm that the confirmation message made it through to the end user.
- $this->assertRaw(t('%name has been disabled.', ['%name' => $account->getUsername()]), "Confirmation message displayed to user.");
+ $this->assertRaw(t('%name has been disabled.', ['%name' => $account->getDisplayName()]), "Confirmation message displayed to user.");
}
/**
@@ -365,7 +365,7 @@ public function testUserAnonymize() {
$this->assertEqual($test_comment->getAuthorName(), $anonymous_user->getDisplayName(), 'Comment of the user has been attributed to anonymous user name.');
// Confirm that the confirmation message made it through to the end user.
- $this->assertRaw(t('%name has been deleted.', ['%name' => $account->getUsername()]), "Confirmation message displayed to user.");
+ $this->assertRaw(t('%name has been deleted.', ['%name' => $account->getDisplayName()]), "Confirmation message displayed to user.");
}
/**
@@ -483,7 +483,7 @@ public function testUserDelete() {
$this->assertFalse(Comment::load($comment->id()), 'Comment of the user has been deleted.');
// Confirm that the confirmation message made it through to the end user.
- $this->assertRaw(t('%name has been deleted.', ['%name' => $account->getUsername()]), "Confirmation message displayed to user.");
+ $this->assertRaw(t('%name has been deleted.', ['%name' => $account->getDisplayName()]), "Confirmation message displayed to user.");
}
/**
@@ -502,12 +502,12 @@ public function testUserCancelByAdmin() {
// Delete regular user.
$this->drupalGet('user/' . $account->id() . '/edit');
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
- $this->assertRaw(t('Are you sure you want to cancel the account %name?', ['%name' => $account->getUsername()]), 'Confirmation form to cancel account displayed.');
+ $this->assertRaw(t('Are you sure you want to cancel the account %name?', ['%name' => $account->getDisplayName()]), 'Confirmation form to cancel account displayed.');
$this->assertText(t('Select the method to cancel the account above.'), 'Allows to select account cancellation method.');
// Confirm deletion.
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
- $this->assertRaw(t('%name has been deleted.', ['%name' => $account->getUsername()]), 'User deleted.');
+ $this->assertRaw(t('%name has been deleted.', ['%name' => $account->getDisplayName()]), 'User deleted.');
$this->assertFalse(User::load($account->id()), 'User is not found in the database.');
}
@@ -530,12 +530,12 @@ public function testUserWithoutEmailCancelByAdmin() {
// Delete regular user without email address.
$this->drupalGet('user/' . $account->id() . '/edit');
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
- $this->assertRaw(t('Are you sure you want to cancel the account %name?', ['%name' => $account->getUsername()]), 'Confirmation form to cancel account displayed.');
+ $this->assertRaw(t('Are you sure you want to cancel the account %name?', ['%name' => $account->getDisplayName()]), 'Confirmation form to cancel account displayed.');
$this->assertText(t('Select the method to cancel the account above.'), 'Allows to select account cancellation method.');
// Confirm deletion.
$this->drupalPostForm(NULL, NULL, t('Cancel account'));
- $this->assertRaw(t('%name has been deleted.', ['%name' => $account->getUsername()]), 'User deleted.');
+ $this->assertRaw(t('%name has been deleted.', ['%name' => $account->getDisplayName()]), 'User deleted.');
$this->assertFalse(User::load($account->id()), 'User is not found in the database.');
}
@@ -577,7 +577,7 @@ public function testMassUserCancelByAdmin() {
$this->drupalPostForm(NULL, NULL, t('Cancel accounts'));
$status = TRUE;
foreach ($users as $account) {
- $status = $status && (strpos($this->content, $account->getUsername() . ' has been deleted.') !== FALSE);
+ $status = $status && (strpos($this->content, $account->getDisplayName() . ' has been deleted.') !== FALSE);
$user_storage->resetCache([$account->id()]);
$status = $status && !$user_storage->load($account->id());
}
diff --git a/core/modules/user/src/Tests/UserEditTest.php b/core/modules/user/src/Tests/UserEditTest.php
index 6f1e369..df12d6e 100644
--- a/core/modules/user/src/Tests/UserEditTest.php
+++ b/core/modules/user/src/Tests/UserEditTest.php
@@ -21,7 +21,7 @@ public function testUserEdit() {
$this->drupalLogin($user1);
// Test that error message appears when attempting to use a non-unique user name.
- $edit['name'] = $user2->getUsername();
+ $edit['name'] = $user2->getDisplayName();
$this->drupalPostForm("user/" . $user1->id() . "/edit", $edit, t('Save'));
$this->assertRaw(t('The username %name is already taken.', ['%name' => $edit['name']]));
diff --git a/core/modules/user/src/Tests/UserLoginTest.php b/core/modules/user/src/Tests/UserLoginTest.php
index d92c1c7..c8022c0 100644
--- a/core/modules/user/src/Tests/UserLoginTest.php
+++ b/core/modules/user/src/Tests/UserLoginTest.php
@@ -23,7 +23,7 @@ public function testLoginCacheTagsAndDestination() {
$user = $this->drupalCreateUser([]);
$this->drupalGet('user/login', ['query' => ['destination' => 'foo']]);
- $edit = ['name' => $user->getUserName(), 'pass' => $user->pass_raw];
+ $edit = ['name' => $user->getDisplayName(), 'pass' => $user->pass_raw];
$this->drupalPostForm(NULL, $edit, t('Log in'));
$this->assertUrl('foo', [], 'Redirected to the correct URL');
}
@@ -156,7 +156,7 @@ public function testPasswordRehashOnLogin() {
*/
public function assertFailedLogin($account, $flood_trigger = NULL) {
$edit = [
- 'name' => $account->getUsername(),
+ 'name' => $account->getDisplayName(),
'pass' => $account->pass_raw,
];
$this->drupalPostForm('user/login', $edit, t('Log in'));
diff --git a/core/modules/user/src/Tests/UserPasswordResetTest.php b/core/modules/user/src/Tests/UserPasswordResetTest.php
index 528d38b..b13f38b 100644
--- a/core/modules/user/src/Tests/UserPasswordResetTest.php
+++ b/core/modules/user/src/Tests/UserPasswordResetTest.php
@@ -85,12 +85,12 @@ public function testUserPasswordReset() {
$this->assertEqual(count($this->drupalGetMails(['id' => 'user_password_reset'])), 0, 'No email was sent when requesting a password for an invalid account.');
// Reset the password by username via the password reset page.
- $edit['name'] = $this->account->getUsername();
+ $edit['name'] = $this->account->getDisplayName();
$this->drupalPostForm(NULL, $edit, t('Submit'));
// Verify that the user was sent an email.
$this->assertMail('to', $this->account->getEmail(), 'Password email sent to user.');
- $subject = t('Replacement login information for @username at @site', ['@username' => $this->account->getUsername(), '@site' => $this->config('system.site')->get('name')]);
+ $subject = t('Replacement login information for @username at @site', ['@username' => $this->account->getDisplayName(), '@site' => $this->config('system.site')->get('name')]);
$this->assertMail('subject', $subject, 'Password reset email subject is correct.');
$resetURL = $this->getResetURL();
@@ -105,14 +105,14 @@ public function testUserPasswordReset() {
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'));
// Check the one-time login page.
- $this->assertText($this->account->getUsername(), 'One-time login page contains the correct username.');
+ $this->assertText($this->account->getDisplayName(), 'One-time login page contains the correct username.');
$this->assertText(t('This login can be used only once.'), 'Found warning about one-time login.');
$this->assertTitle(t('Reset password | Drupal'), 'Page title is "Reset password".');
// Check successful login.
$this->drupalPostForm(NULL, NULL, t('Log in'));
$this->assertLink(t('Log out'));
- $this->assertTitle(t('@name | @site', ['@name' => $this->account->getUsername(), '@site' => $this->config('system.site')->get('name')]), 'Logged in using password reset link.');
+ $this->assertTitle(t('@name | @site', ['@name' => $this->account->getDisplayName(), '@site' => $this->config('system.site')->get('name')]), 'Logged in using password reset link.');
// Make sure the ajax request from uploading a user picture does not
// invalidate the reset token.
@@ -174,14 +174,14 @@ public function testUserPasswordReset() {
$this->drupalGet('user/password');
// Count email messages before to compare with after.
$before = count($this->drupalGetMails(['id' => 'user_password_reset']));
- $edit = ['name' => $blocked_account->getUsername()];
+ $edit = ['name' => $blocked_account->getDisplayName()];
$this->drupalPostForm(NULL, $edit, t('Submit'));
- $this->assertRaw(t('%name is blocked or has not been activated yet.', ['%name' => $blocked_account->getUsername()]), 'Notified user blocked accounts can not request a new password');
+ $this->assertRaw(t('%name is blocked or has not been activated yet.', ['%name' => $blocked_account->getDisplayName()]), 'Notified user blocked accounts can not request a new password');
$this->assertTrue(count($this->drupalGetMails(['id' => 'user_password_reset'])) === $before, 'No email was sent when requesting password reset for a blocked account');
// Verify a password reset link is invalidated when the user's email address changes.
$this->drupalGet('user/password');
- $edit = ['name' => $this->account->getUsername()];
+ $edit = ['name' => $this->account->getDisplayName()];
$this->drupalPostForm(NULL, $edit, t('Submit'));
$old_email_reset_link = $this->getResetURL();
$this->account->setEmail("1" . $this->account->getEmail());
@@ -193,12 +193,12 @@ public function testUserPasswordReset() {
// Verify a password reset link will automatically log a user when /login is
// appended.
$this->drupalGet('user/password');
- $edit = ['name' => $this->account->getUsername()];
+ $edit = ['name' => $this->account->getDisplayName()];
$this->drupalPostForm(NULL, $edit, t('Submit'));
$reset_url = $this->getResetURL();
$this->drupalGet($reset_url . '/login');
$this->assertLink(t('Log out'));
- $this->assertTitle(t('@name | @site', ['@name' => $this->account->getUsername(), '@site' => $this->config('system.site')->get('name')]), 'Logged in using password reset link.');
+ $this->assertTitle(t('@name | @site', ['@name' => $this->account->getDisplayName(), '@site' => $this->config('system.site')->get('name')]), 'Logged in using password reset link.');
// Ensure blocked and deleted accounts can't access the user.reset.login
// route.
@@ -243,7 +243,7 @@ public function testUserPasswordResetLoggedIn() {
$this->drupalGet($resetURL);
$this->assertRaw(new FormattableMarkup(
'Another user (%other_user) is already logged into the site on this computer, but you tried to use a one-time link for user %resetting_user. Please log out and try using the link again.',
- ['%other_user' => $this->account->getUsername(), '%resetting_user' => $another_account->getUsername(), ':logout' => Url::fromRoute('user.logout')->toString()]
+ ['%other_user' => $this->account->getDisplayName(), '%resetting_user' => $another_account->getDisplayName(), ':logout' => Url::fromRoute('user.logout')->toString()]
));
$another_account->delete();
@@ -332,7 +332,7 @@ public function testResetImpersonation() {
$attack_reset_url = str_replace("user/reset/{$user1->id()}", "user/reset/{$user2->id()}", $reset_url);
$this->drupalGet($attack_reset_url);
$this->drupalPostForm(NULL, NULL, t('Log in'));
- $this->assertNoText($user2->getUsername(), 'The invalid password reset page does not show the user name.');
+ $this->assertNoText($user2->getDisplayName(), 'The invalid password reset page does not show the user name.');
$this->assertUrl('user/password', [], 'The user is redirected to the password reset request page.');
$this->assertText('You have tried to use a one-time login link that has either been used or is no longer valid. Please request a new one using the form below.');
}
diff --git a/core/modules/user/src/Tests/UserPictureTest.php b/core/modules/user/src/Tests/UserPictureTest.php
index 6d546f0..8eb8274 100644
--- a/core/modules/user/src/Tests/UserPictureTest.php
+++ b/core/modules/user/src/Tests/UserPictureTest.php
@@ -96,7 +96,7 @@ public function testPictureOnNodeComment() {
$image_style_id = $this->config('core.entity_view_display.user.user.compact')->get('content.user_picture.settings.image_style');
$style = ImageStyle::load($image_style_id);
$image_url = file_url_transform_relative($style->buildUrl($file->getfileUri()));
- $alt_text = 'Profile picture for user ' . $this->webUser->getUsername();
+ $alt_text = 'Profile picture for user ' . $this->webUser->getDisplayName();
// Verify that the image is displayed on the node page.
$this->drupalGet('node/' . $node->id());
diff --git a/core/modules/user/src/Tests/UserRegistrationTest.php b/core/modules/user/src/Tests/UserRegistrationTest.php
index ca7a4f0..32a0ebb 100644
--- a/core/modules/user/src/Tests/UserRegistrationTest.php
+++ b/core/modules/user/src/Tests/UserRegistrationTest.php
@@ -252,7 +252,7 @@ public function testRegistrationDefaultValues() {
$accounts = $this->container->get('entity_type.manager')->getStorage('user')
->loadByProperties(['name' => $name, 'mail' => $mail]);
$new_user = reset($accounts);
- $this->assertEqual($new_user->getUsername(), $name, 'Username matches.');
+ $this->assertEqual($new_user->getDisplayName(), $name, 'Username matches.');
$this->assertEqual($new_user->getEmail(), $mail, 'Email address matches.');
$this->assertTrue(($new_user->getCreatedTime() > REQUEST_TIME - 20 ), 'Correct creation time.');
$this->assertEqual($new_user->isActive(), $config_user_settings->get('register') == USER_REGISTER_VISITORS ? 1 : 0, 'Correct status field.');
@@ -271,9 +271,9 @@ public function testRegistrationDefaultValues() {
public function testUniqueFields() {
$account = $this->drupalCreateUser();
- $edit = ['mail' => 'test@example.com', 'name' => $account->getUsername()];
+ $edit = ['mail' => 'test@example.com', 'name' => $account->getDisplayName()];
$this->drupalPostForm('user/register', $edit, t('Create new account'));
- $this->assertRaw(SafeMarkup::format('The username %value is already taken.', ['%value' => $account->getUsername()]));
+ $this->assertRaw(SafeMarkup::format('The username %value is already taken.', ['%value' => $account->getDisplayName()]));
$edit = ['mail' => $account->getEmail(), 'name' => $this->randomString()];
$this->drupalPostForm('user/register', $edit, t('Create new account'));
diff --git a/core/modules/user/src/Tests/Views/ArgumentValidateTest.php b/core/modules/user/src/Tests/Views/ArgumentValidateTest.php
index 3365bd8..085c512 100644
--- a/core/modules/user/src/Tests/Views/ArgumentValidateTest.php
+++ b/core/modules/user/src/Tests/Views/ArgumentValidateTest.php
@@ -64,7 +64,7 @@ public function testArgumentValidateUserName() {
$view = Views::getView('test_view_argument_validate_username');
$this->executeView($view);
- $this->assertTrue($view->argument['null']->validateArgument($account->getUsername()));
+ $this->assertTrue($view->argument['null']->validateArgument($account->getDisplayName()));
// Reset argument validation.
$view->argument['null']->argument_validated = NULL;
// Fail for a valid string, but for a user that doesn't exist
diff --git a/core/modules/user/tests/modules/user_access_test/user_access_test.module b/core/modules/user/tests/modules/user_access_test/user_access_test.module
index 470a76a..2567481 100644
--- a/core/modules/user/tests/modules/user_access_test/user_access_test.module
+++ b/core/modules/user/tests/modules/user_access_test/user_access_test.module
@@ -12,11 +12,11 @@
* Implements hook_ENTITY_TYPE_access() for entity type "user".
*/
function user_access_test_user_access(User $entity, $operation, $account) {
- if ($entity->getUsername() == "no_edit" && $operation == "update") {
+ if ($entity->getDisplayName() == "no_edit" && $operation == "update") {
// Deny edit access.
return AccessResult::forbidden();
}
- if ($entity->getUsername() == "no_delete" && $operation == "delete") {
+ if ($entity->getDisplayName() == "no_delete" && $operation == "delete") {
// Deny delete access.
return AccessResult::forbidden();
}
diff --git a/core/modules/user/tests/src/Functional/UserEntityCallbacksTest.php b/core/modules/user/tests/src/Functional/UserEntityCallbacksTest.php
index feea805..ee2a0bc 100644
--- a/core/modules/user/tests/src/Functional/UserEntityCallbacksTest.php
+++ b/core/modules/user/tests/src/Functional/UserEntityCallbacksTest.php
@@ -45,20 +45,20 @@ protected function setUp() {
* Test label callback.
*/
public function testLabelCallback() {
- $this->assertEqual($this->account->label(), $this->account->getUsername(), 'The username should be used as label');
+ $this->assertEqual($this->account->label(), $this->account->getDisplayName(), 'The username should be used as label');
// Setup a random anonymous name to be sure the name is used.
$name = $this->randomMachineName();
$this->config('user.settings')->set('anonymous', $name)->save();
$this->assertEqual($this->anonymous->label(), $name, 'The variable anonymous should be used for name of uid 0');
$this->assertEqual($this->anonymous->getDisplayName(), $name, 'The variable anonymous should be used for display name of uid 0');
- $this->assertEqual($this->anonymous->getUserName(), '', 'The raw anonymous user name should be empty string');
+ $this->assertEqual($this->anonymous->getDisplayName(), '', 'The raw anonymous user name should be empty string');
// Set to test the altered username.
\Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE);
$this->assertEqual($this->account->getDisplayName(), '' . $this->account->id() . '', 'The user display name should be altered.');
- $this->assertEqual($this->account->getUsername(), $this->account->name->value, 'The user name should not be altered.');
+ $this->assertEqual($this->account->getDisplayName(), $this->account->name->value, 'The user name should not be altered.');
}
}
diff --git a/core/modules/user/tests/src/Functional/UserLoginHttpTest.php b/core/modules/user/tests/src/Functional/UserLoginHttpTest.php
index 29b9727..ac2d4a7 100644
--- a/core/modules/user/tests/src/Functional/UserLoginHttpTest.php
+++ b/core/modules/user/tests/src/Functional/UserLoginHttpTest.php
@@ -109,7 +109,7 @@ public function testLogin() {
// Grant the user administer users permissions to they can see the
// 'roles' field.
$account = $this->drupalCreateUser(['administer users']);
- $name = $account->getUsername();
+ $name = $account->getDisplayName();
$pass = $account->passRaw;
$login_status_url = $this->getLoginStatusUrlString($format);
@@ -236,12 +236,12 @@ public function testGlobalLoginFloodControl() {
// Try 2 failed logins.
for ($i = 0; $i < 2; $i++) {
- $response = $this->loginRequest($incorrect_user->getUsername(), $incorrect_user->passRaw);
+ $response = $this->loginRequest($incorrect_user->getDisplayName(), $incorrect_user->passRaw);
$this->assertEquals('400', $response->getStatusCode());
}
// IP limit has reached to its limit. Even valid user credentials will fail.
- $response = $this->loginRequest($user->getUsername(), $user->passRaw);
+ $response = $this->loginRequest($user->getDisplayName(), $user->passRaw);
$this->assertHttpResponseWithMessage($response, '403', 'Access is blocked because of IP based flood prevention.');
}
@@ -300,18 +300,18 @@ public function testPerUserLoginFloodControl() {
// Try 2 failed logins.
for ($i = 0; $i < 2; $i++) {
- $response = $this->loginRequest($incorrect_user1->getUsername(), $incorrect_user1->passRaw);
+ $response = $this->loginRequest($incorrect_user1->getDisplayName(), $incorrect_user1->passRaw);
$this->assertHttpResponseWithMessage($response, 400, 'Sorry, unrecognized username or password.');
}
// A successful login will reset the per-user flood control count.
- $response = $this->loginRequest($user1->getUsername(), $user1->passRaw);
+ $response = $this->loginRequest($user1->getDisplayName(), $user1->passRaw);
$result_data = $this->serializer->decode($response->getBody(), 'json');
$this->logoutRequest('json', $result_data['logout_token']);
// Try 3 failed logins for user 1, they will not trigger flood control.
for ($i = 0; $i < 3; $i++) {
- $response = $this->loginRequest($incorrect_user1->getUsername(), $incorrect_user1->passRaw);
+ $response = $this->loginRequest($incorrect_user1->getDisplayName(), $incorrect_user1->passRaw);
$this->assertHttpResponseWithMessage($response, 400, 'Sorry, unrecognized username or password.');
}
@@ -322,7 +322,7 @@ public function testPerUserLoginFloodControl() {
// Try one more attempt for user 1, it should be rejected, even if the
// correct password has been used.
- $response = $this->loginRequest($user1->getUsername(), $user1->passRaw);
+ $response = $this->loginRequest($user1->getDisplayName(), $user1->passRaw);
// Depending on the uid_only setting the error message will be different.
if ($uid_only_setting) {
$excepted_message = 'There have been more than 3 failed login attempts for this account. It is temporarily blocked. Try again later or request a new password.';
@@ -374,7 +374,7 @@ public function testLogoutCsrfProtection() {
$client = \Drupal::httpClient();
$login_status_url = $this->getLoginStatusUrlString();
$account = $this->drupalCreateUser();
- $name = $account->getUsername();
+ $name = $account->getDisplayName();
$pass = $account->passRaw;
$response = $this->loginRequest($name, $pass);
diff --git a/core/modules/user/tests/src/Functional/UserSearchTest.php b/core/modules/user/tests/src/Functional/UserSearchTest.php
index 8ce0319..54b1d61 100644
--- a/core/modules/user/tests/src/Functional/UserSearchTest.php
+++ b/core/modules/user/tests/src/Functional/UserSearchTest.php
@@ -38,7 +38,7 @@ public function testUserSearch() {
$this->assertText('no results', 'Non-matching search gave appropriate message');
// Verify that a user with search permission can search for users by name.
- $keys = $user1->getUsername();
+ $keys = $user1->getDisplayName();
$edit = ['keys' => $keys];
$this->drupalPostForm('search/user', $edit, t('Search'));
$this->assertLink($keys, 0, 'Search by username worked for non-admin user');
@@ -63,23 +63,23 @@ public function testUserSearch() {
$edit = ['keys' => $keys];
$this->drupalPostForm('search/user', $edit, t('Search'));
$this->assertText($keys, 'Search by email works for administrative user');
- $this->assertText($user2->getUsername(), 'Search by email resulted in username on page for administrative user');
+ $this->assertText($user2->getDisplayName(), 'Search by email resulted in username on page for administrative user');
// Verify that a substring works too for email.
$subkey = substr($keys, 1, 5);
$edit = ['keys' => $subkey];
$this->drupalPostForm('search/user', $edit, t('Search'));
$this->assertText($keys, 'Search by email substring works for administrative user');
- $this->assertText($user2->getUsername(), 'Search by email substring resulted in username on page for administrative user');
+ $this->assertText($user2->getDisplayName(), 'Search by email substring resulted in username on page for administrative user');
// Verify that wildcard search works for email
$subkey = substr($keys, 0, 2) . '*' . substr($keys, 4, 2);
$edit = ['keys' => $subkey];
$this->drupalPostForm('search/user', $edit, t('Search'));
- $this->assertText($user2->getUsername(), 'Search for email wildcard resulted in username on page for administrative user');
+ $this->assertText($user2->getDisplayName(), 'Search for email wildcard resulted in username on page for administrative user');
// Verify that if they search by user name, they see email address too.
- $keys = $user1->getUsername();
+ $keys = $user1->getDisplayName();
$edit = ['keys' => $keys];
$this->drupalPostForm('search/user', $edit, t('Search'));
$this->assertText($keys, 'Search by username works for admin user');
@@ -92,14 +92,14 @@ public function testUserSearch() {
// Verify that users with "administer users" permissions can see blocked
// accounts in search results.
- $edit = ['keys' => $blocked_user->getUsername()];
+ $edit = ['keys' => $blocked_user->getDisplayName()];
$this->drupalPostForm('search/user', $edit, t('Search'));
- $this->assertText($blocked_user->getUsername(), 'Blocked users are listed on the user search results for users with the "administer users" permission.');
+ $this->assertText($blocked_user->getDisplayName(), 'Blocked users are listed on the user search results for users with the "administer users" permission.');
// Verify that users without "administer users" permissions do not see
// blocked accounts in search results.
$this->drupalLogin($user1);
- $edit = ['keys' => $blocked_user->getUsername()];
+ $edit = ['keys' => $blocked_user->getDisplayName()];
$this->drupalPostForm('search/user', $edit, t('Search'));
$this->assertText(t('Your search yielded no results.'), 'Blocked users are hidden from the user search results.');
diff --git a/core/modules/user/tests/src/Kernel/Migrate/MigrateUserAdminPassTest.php b/core/modules/user/tests/src/Kernel/Migrate/MigrateUserAdminPassTest.php
index 85cd761..9daf502 100644
--- a/core/modules/user/tests/src/Kernel/Migrate/MigrateUserAdminPassTest.php
+++ b/core/modules/user/tests/src/Kernel/Migrate/MigrateUserAdminPassTest.php
@@ -94,14 +94,14 @@ public function testAdminPasswordPreserved() {
// Verify that admin username and email were changed, but password was not.
/** @var \Drupal\user\Entity\User $admin_account */
$admin_account = User::load(1);
- $this->assertIdentical($admin_account->getUsername(), 'site_admin');
+ $this->assertIdentical($admin_account->getDisplayName(), 'site_admin');
$this->assertIdentical($admin_account->getEmail(), 'site_admin@example.com');
$this->assertIdentical($admin_account->getPassword(), $this->originalPasswords[1]);
// Verify that everything changed for the regular user.
/** @var \Drupal\user\Entity\User $user_account */
$user_account = User::load(2);
- $this->assertIdentical($user_account->getUsername(), 'random_user');
+ $this->assertIdentical($user_account->getDisplayName(), 'random_user');
$this->assertIdentical($user_account->getEmail(), 'random_user@example.com');
$this->assertNotIdentical($user_account->getPassword(), $this->originalPasswords[2]);
}
diff --git a/core/modules/user/user.module b/core/modules/user/user.module
index b865e95..b821741 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -402,7 +402,7 @@ function user_user_view_alter(array &$build, UserInterface $account, EntityViewD
foreach (Element::children($build['user_picture']) as $key) {
$item = $build['user_picture'][$key]['#item'];
if (!$item->get('alt')->getValue()) {
- $item->get('alt')->setValue(\Drupal::translation()->translate('Profile picture for user @username', ['@username' => $account->getUsername()]));
+ $item->get('alt')->setValue(\Drupal::translation()->translate('Profile picture for user @username', ['@username' => $account->getDisplayName()]));
}
}
}
@@ -485,7 +485,7 @@ function template_preprocess_username(&$variables) {
// their own shortening logic or add markup. If they do so, they must ensure
// that $variables['name'] is safe for printing.
$name = $account->getDisplayName();
- $variables['name_raw'] = $account->getUsername();
+ $variables['name_raw'] = $account->getDisplayName();
if (Unicode::strlen($name) > 20) {
$name = Unicode::truncate($name, 15, FALSE, TRUE);
$variables['truncated'] = TRUE;
@@ -542,7 +542,7 @@ function template_preprocess_username(&$variables) {
*/
function user_login_finalize(UserInterface $account) {
\Drupal::currentUser()->setAccount($account);
- \Drupal::logger('user')->notice('Session opened for %name.', ['%name' => $account->getUsername()]);
+ \Drupal::logger('user')->notice('Session opened for %name.', ['%name' => $account->getDisplayName()]);
// Update the user table timestamp noting user has logged in.
// This is also used to invalidate one-time login links.
$account->setLastLoginTime(REQUEST_TIME);
@@ -1273,7 +1273,7 @@ function user_form_process_password_confirm($element) {
'fair' => t('Fair'),
'good' => t('Good'),
'strong' => t('Strong'),
- 'username' => \Drupal::currentUser()->getUsername(),
+ 'username' => \Drupal::currentUser()->getDisplayName(),
];
}
diff --git a/core/modules/views/tests/src/Kernel/Plugin/RelationshipTest.php b/core/modules/views/tests/src/Kernel/Plugin/RelationshipTest.php
index 802befe..80e242d 100644
--- a/core/modules/views/tests/src/Kernel/Plugin/RelationshipTest.php
+++ b/core/modules/views/tests/src/Kernel/Plugin/RelationshipTest.php
@@ -170,8 +170,8 @@ public function testRelationshipRender() {
// Check that the output contains correct values.
$xpath = '//div[@class="views-row" and div[@class="views-field views-field-id"]=:id and div[@class="views-field views-field-author"]=:author]';
- $this->assertEqual(1, count($this->xpath($xpath, [':id' => 1, ':author' => $author1->getUsername()])));
- $this->assertEqual(1, count($this->xpath($xpath, [':id' => 2, ':author' => $author2->getUsername()])));
+ $this->assertEqual(1, count($this->xpath($xpath, [':id' => 1, ':author' => $author1->getDisplayName()])));
+ $this->assertEqual(1, count($this->xpath($xpath, [':id' => 2, ':author' => $author2->getDisplayName()])));
$this->assertEqual(1, count($this->xpath($xpath, [':id' => 3, ':author' => ''])));
}
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php
index e0bf655..6a459d7 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php
@@ -134,19 +134,19 @@ protected function doTestReadWrite($entity_type) {
$this->assertTrue($entity->user_id[0] instanceof FieldItemInterface, format_string('%entity_type: Field item implements interface', ['%entity_type' => $entity_type]));
$this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', ['%entity_type' => $entity_type]));
- $this->assertEqual($this->entityUser->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', ['%entity_type' => $entity_type]));
+ $this->assertEqual($this->entityUser->getDisplayName(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', ['%entity_type' => $entity_type]));
// Change the assigned user by entity.
$new_user1 = $this->createUser();
$entity->user_id->entity = $new_user1;
$this->assertEqual($new_user1->id(), $entity->user_id->target_id, format_string('%entity_type: Updated user id can be read.', ['%entity_type' => $entity_type]));
- $this->assertEqual($new_user1->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated username value can be read.', ['%entity_type' => $entity_type]));
+ $this->assertEqual($new_user1->getDisplayName(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated username value can be read.', ['%entity_type' => $entity_type]));
// Change the assigned user by id.
$new_user2 = $this->createUser();
$entity->user_id->target_id = $new_user2->id();
$this->assertEqual($new_user2->id(), $entity->user_id->target_id, format_string('%entity_type: Updated user id can be read.', ['%entity_type' => $entity_type]));
- $this->assertEqual($new_user2->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated username value can be read.', ['%entity_type' => $entity_type]));
+ $this->assertEqual($new_user2->getDisplayName(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated username value can be read.', ['%entity_type' => $entity_type]));
// Try unsetting a field property.
$entity->name->value = NULL;
@@ -159,12 +159,12 @@ protected function doTestReadWrite($entity_type) {
// Change the assigned user by entity.
$entity->user_id->first()->get('entity')->setValue($new_user2);
$this->assertEqual($new_user2->id(), $entity->user_id->target_id, format_string('%entity_type: Updated user id can be read.', ['%entity_type' => $entity_type]));
- $this->assertEqual($new_user2->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated user name value can be read.', ['%entity_type' => $entity_type]));
+ $this->assertEqual($new_user2->getDisplayName(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated user name value can be read.', ['%entity_type' => $entity_type]));
// Change the assigned user by id.
$entity->user_id->first()->get('target_id')->setValue($new_user2->id());
$this->assertEqual($new_user2->id(), $entity->user_id->target_id, format_string('%entity_type: Updated user id can be read.', ['%entity_type' => $entity_type]));
- $this->assertEqual($new_user2->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated user name value can be read.', ['%entity_type' => $entity_type]));
+ $this->assertEqual($new_user2->getDisplayName(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated user name value can be read.', ['%entity_type' => $entity_type]));
// Try unsetting a field.
$entity->name->first()->get('value')->setValue(NULL);
@@ -269,7 +269,7 @@ protected function doTestReadWrite($entity_type) {
]);
$this->assertEqual($this->entityName, $entity->name->value, format_string('%entity_type: Name value can be read.', ['%entity_type' => $entity_type]));
$this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', ['%entity_type' => $entity_type]));
- $this->assertEqual($this->entityUser->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', ['%entity_type' => $entity_type]));
+ $this->assertEqual($this->entityUser->getDisplayName(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', ['%entity_type' => $entity_type]));
$this->assertEqual($this->entityFieldText, $entity->field_test_text->value, format_string('%entity_type: Text field can be read.', ['%entity_type' => $entity_type]));
// Tests copying field values by assigning the TypedData objects.
@@ -389,7 +389,7 @@ protected function doTestSave($entity_type) {
$this->assertEqual('en', $entity->{$langcode_key}->value, format_string('%entity_type: Language code can be read.', ['%entity_type' => $entity_type]));
$this->assertEqual(\Drupal::languageManager()->getLanguage('en'), $entity->{$langcode_key}->language, format_string('%entity_type: Language object can be read.', ['%entity_type' => $entity_type]));
$this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', ['%entity_type' => $entity_type]));
- $this->assertEqual($this->entityUser->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', ['%entity_type' => $entity_type]));
+ $this->assertEqual($this->entityUser->getDisplayName(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', ['%entity_type' => $entity_type]));
$this->assertEqual($this->entityFieldText, $entity->field_test_text->value, format_string('%entity_type: Text field can be read.', ['%entity_type' => $entity_type]));
}
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryRelationshipTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryRelationshipTest.php
index 0bb5b16..155f07c 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryRelationshipTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryRelationshipTest.php
@@ -120,12 +120,12 @@ public function testQuery() {
// This returns the 0th entity as that's the only one pointing to the 0th
// account.
$this->queryResults = $this->factory->get('entity_test')
- ->condition("user_id.entity.name", $this->accounts[0]->getUsername())
+ ->condition("user_id.entity.name", $this->accounts[0]->getDisplayName())
->execute();
$this->assertResults([0]);
// This returns the 1st and 2nd entity as those point to the 1st account.
$this->queryResults = $this->factory->get('entity_test')
- ->condition("user_id.entity.name", $this->accounts[0]->getUsername(), '<>')
+ ->condition("user_id.entity.name", $this->accounts[0]->getDisplayName(), '<>')
->execute();
$this->assertResults([1, 2]);
// This returns all three entities because all of them point to an
@@ -159,12 +159,12 @@ public function testQuery() {
// This returns the 0th entity as that's only one pointing to the 0th
// account.
$this->queryResults = $this->factory->get('entity_test')
- ->condition("user_id.entity:user.name", $this->accounts[0]->getUsername())
+ ->condition("user_id.entity:user.name", $this->accounts[0]->getDisplayName())
->execute();
$this->assertResults([0]);
// This returns the 1st and 2nd entity as those point to the 1st account.
$this->queryResults = $this->factory->get('entity_test')
- ->condition("user_id.entity:user.name", $this->accounts[0]->getUsername(), '<>')
+ ->condition("user_id.entity:user.name", $this->accounts[0]->getDisplayName(), '<>')
->execute();
$this->assertResults([1, 2]);
// This returns all three entities because all of them point to an
diff --git a/core/tests/Drupal/KernelTests/Core/Plugin/ContextPluginTest.php b/core/tests/Drupal/KernelTests/Core/Plugin/ContextPluginTest.php
index bd3bba5..4f780bc 100644
--- a/core/tests/Drupal/KernelTests/Core/Plugin/ContextPluginTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Plugin/ContextPluginTest.php
@@ -72,7 +72,7 @@ public function testContext() {
$user = User::create(['name' => $name]);
$plugin->setContextValue('user', $user);
- $this->assertEqual($plugin->getContextValue('user')->getUsername(), $user->getUsername());
+ $this->assertEqual($plugin->getContextValue('user')->getDisplayName(), $user->getDisplayName());
$this->assertEqual($user->label(), $plugin->getTitle());
// Test Optional context handling.
diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php
index 5751368..1c40beb 100644
--- a/core/tests/Drupal/Tests/BrowserTestBase.php
+++ b/core/tests/Drupal/Tests/BrowserTestBase.php
@@ -717,7 +717,7 @@ protected function drupalLogin(AccountInterface $account) {
$this->drupalGet('user/login');
$this->assertSession()->statusCodeEquals(200);
$this->submitForm([
- 'name' => $account->getUsername(),
+ 'name' => $account->getDisplayName(),
'pass' => $account->passRaw,
], t('Log in'));
diff --git a/core/themes/seven/seven.theme b/core/themes/seven/seven.theme
index 91c03e6..215c727 100644
--- a/core/themes/seven/seven.theme
+++ b/core/themes/seven/seven.theme
@@ -180,7 +180,7 @@ function seven_form_node_form_alter(&$form, FormStateInterface $form_state) {
'author' => [
'#type' => 'item',
'#wrapper_attributes' => ['class' => ['author', 'container-inline']],
- '#markup' => '' . t('Author') . '
' . $node->getOwner()->getUsername(),
+ '#markup' => '' . t('Author') . '
' . $node->getOwner()->getDisplayName(),
],
];
$form['revision_information']['#type'] = 'container';