diff --git a/core/core.api.php b/core/core.api.php index 6415c4f..e2de579 100644 --- a/core/core.api.php +++ b/core/core.api.php @@ -1961,7 +1961,7 @@ function hook_mail($key, &$message, $params) { $context = $params['context']; $variables = array( '%site_name' => \Drupal::config('system.site')->get('name'), - '%username' => $account->getDisplayName(), + '%username' => $account->getAccountName(), ); if ($context['hook'] == 'taxonomy') { $entity = $params['entity']; diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index a7dc64f..ecc5e98 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -313,7 +313,7 @@ function drupal_get_path($type, $name) { * names or link URLs into translated text. Variable substitution looks like * this: * @code - * $text = t("@name's blog", array('@name' => $account->getDisplayName())); + * $text = t("@name's blog", array('@name' => $account->getAccountName())); * @endcode * Basically, you can put variables like @name into your string, and t() will * substitute their sanitized values at translation time. (See the diff --git a/core/lib/Drupal/Core/Session/AccountInterface.php b/core/lib/Drupal/Core/Session/AccountInterface.php index e5351c7..fa42de0 100644 --- a/core/lib/Drupal/Core/Session/AccountInterface.php +++ b/core/lib/Drupal/Core/Session/AccountInterface.php @@ -132,7 +132,7 @@ public function getUsername(); * \Drupal\Component\Utility\Html::escape() is called on it before it * is printed to the page or used in a template. */ - public function getDisplayName(); + public function getAccountName(); /** * Returns the email address of this account. diff --git a/core/lib/Drupal/Core/Session/AccountProxy.php b/core/lib/Drupal/Core/Session/AccountProxy.php index 149325d..f088147 100644 --- a/core/lib/Drupal/Core/Session/AccountProxy.php +++ b/core/lib/Drupal/Core/Session/AccountProxy.php @@ -125,8 +125,8 @@ public function getUsername() { /** * {@inheritdoc} */ - public function getDisplayName() { - return $this->getAccount()->getDisplayName(); + public function getAccountName() { + return $this->getAccount()->getAccountName(); } /** diff --git a/core/lib/Drupal/Core/Session/UserSession.php b/core/lib/Drupal/Core/Session/UserSession.php index bbf880b..1b9fcf0 100644 --- a/core/lib/Drupal/Core/Session/UserSession.php +++ b/core/lib/Drupal/Core/Session/UserSession.php @@ -166,7 +166,7 @@ public function getUsername() { /** * {@inheritdoc} */ - public function getDisplayName() { + public function getAccountName() { $name = $this->name ?: \Drupal::config('user.settings')->get('anonymous'); \Drupal::moduleHandler()->alter('user_format_name', $name, $this); return $name; diff --git a/core/modules/action/src/Plugin/Action/EmailAction.php b/core/modules/action/src/Plugin/Action/EmailAction.php index d31d239..b20b774 100644 --- a/core/modules/action/src/Plugin/Action/EmailAction.php +++ b/core/modules/action/src/Plugin/Action/EmailAction.php @@ -185,7 +185,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#default_value' => $this->configuration['message'], '#cols' => '80', '#rows' => '20', - '#description' => t('The message that should be sent. You may include placeholders like [node:title], [user:display-name], [user:name] and [comment:body] to represent data that will be different each time message is sent. Not all placeholders will be available in all contexts.'), + '#description' => t('The message that should be sent. You may include placeholders like [node:title], [user:account-name], [user:name] and [comment:body] to represent data that will be different each time message is sent. Not all placeholders will be available in all contexts.'), ); return $form; } diff --git a/core/modules/action/src/Plugin/Action/MessageAction.php b/core/modules/action/src/Plugin/Action/MessageAction.php index c8ddd4a..4ee3638 100644 --- a/core/modules/action/src/Plugin/Action/MessageAction.php +++ b/core/modules/action/src/Plugin/Action/MessageAction.php @@ -78,7 +78,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#default_value' => $this->configuration['message'], '#required' => TRUE, '#rows' => '8', - '#description' => t('The message to be displayed to the current user. You may include placeholders like [node:title], [user:display-name], [user:name] and [comment:body] to represent data that will be different each time message is sent. Not all placeholders will be available in all contexts.'), + '#description' => t('The message to be displayed to the current user. You may include placeholders like [node:title], [user:account-name], [user:name] and [comment:body] to represent data that will be different each time message is sent. Not all placeholders will be available in all contexts.'), ); return $form; } diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index 5ca686c..b184802 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -126,7 +126,7 @@ function contact_mail($key, &$message, $params) { '!subject' => $contact_message->getSubject(), '!form' => !empty($params['contact_form']) ? $params['contact_form']->label() : NULL, '!form-url' => \Drupal::url('', [], ['absolute' => TRUE, 'language' => $language]), - '!sender-name' => $sender->getDisplayName(), + '!sender-name' => $sender->getAccountName(), ); if ($sender->isAuthenticated()) { $variables['!sender-url'] = $sender->url('canonical', array('absolute' => TRUE, 'language' => $language)); @@ -154,7 +154,7 @@ function contact_mail($key, &$message, $params) { case 'user_mail': case 'user_copy': $variables += array( - '!recipient-name' => $params['recipient']->getDisplayName(), + '!recipient-name' => $params['recipient']->getAccountName(), '!recipient-edit-url' => $params['recipient']->url('edit-form', array('absolute' => TRUE, 'language' => $language)), ); $message['subject'] .= t('[!site-name] !subject', $variables, $options); diff --git a/core/modules/contact/src/Controller/ContactController.php b/core/modules/contact/src/Controller/ContactController.php index 19a1c22..d9d8472 100644 --- a/core/modules/contact/src/Controller/ContactController.php +++ b/core/modules/contact/src/Controller/ContactController.php @@ -117,7 +117,7 @@ public function contactPersonalPage(UserInterface $user) { )); $form = $this->entityFormBuilder()->getForm($message); - $form['#title'] = $this->t('Contact @username', array('@username' => $user->getDisplayName())); + $form['#title'] = $this->t('Contact @username', array('@username' => $user->getAccountName())); $form['#cache']['contexts'][] = 'user.permissions'; return $form; } diff --git a/core/modules/file/src/Tests/FileTokenReplaceTest.php b/core/modules/file/src/Tests/FileTokenReplaceTest.php index 93a6c67..193e472 100644 --- a/core/modules/file/src/Tests/FileTokenReplaceTest.php +++ b/core/modules/file/src/Tests/FileTokenReplaceTest.php @@ -56,7 +56,7 @@ function testFileTokenReplacement() { $tests['[file:created:short]'] = format_date($file->getCreatedTime(), 'short', '', NULL, $language_interface->getId()); $tests['[file:changed]'] = format_date($file->getChangedTime(), 'medium', '', NULL, $language_interface->getId()); $tests['[file:changed:short]'] = format_date($file->getChangedTime(), 'short', '', NULL, $language_interface->getId()); - $tests['[file:owner]'] = Html::escape($this->adminUser->getDisplayName()); + $tests['[file:owner]'] = Html::escape($this->adminUser->getAccountName()); $tests['[file:owner:uid]'] = $file->getOwnerId(); $base_bubbleable_metadata = BubbleableMetadata::createFromObject($file); diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 1cdb065..bafa81b 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -456,7 +456,7 @@ function template_preprocess_forums(&$variables) { } $forum_submitted = array('#theme' => 'forum_submitted', '#topic' => (object) array( 'uid' => $topic->getOwnerId(), - 'name' => $topic->getOwner()->getDisplayName(), + 'name' => $topic->getOwner()->getAccountName(), 'created' => $topic->getCreatedTime(), )); $variables['topics'][$id]->submitted = drupal_render($forum_submitted); diff --git a/core/modules/node/src/Plugin/views/row/Rss.php b/core/modules/node/src/Plugin/views/row/Rss.php index 97390af..8d961fc 100644 --- a/core/modules/node/src/Plugin/views/row/Rss.php +++ b/core/modules/node/src/Plugin/views/row/Rss.php @@ -122,7 +122,7 @@ public function render($row) { ), array( 'key' => 'dc:creator', - 'value' => $node->getOwner()->getDisplayName(), + 'value' => $node->getOwner()->getAccountName(), ), array( 'key' => 'guid', diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module index aa5a6d0..3074649 100644 --- a/core/modules/rdf/rdf.module +++ b/core/modules/rdf/rdf.module @@ -378,7 +378,7 @@ function rdf_preprocess_user(&$variables) { '#attributes' => array( 'about' => $account->url(), 'property' => $name_mapping['properties'], - 'content' => $account->getDisplayName(), + 'content' => $account->getAccountName(), 'lang' => '', ), ); diff --git a/core/modules/shortcut/src/Form/SwitchShortcutSet.php b/core/modules/shortcut/src/Form/SwitchShortcutSet.php index e0b214a..c938e1f 100644 --- a/core/modules/shortcut/src/Form/SwitchShortcutSet.php +++ b/core/modules/shortcut/src/Form/SwitchShortcutSet.php @@ -207,7 +207,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { /* @var \Drupal\shortcut\Entity\ShortcutSet $set */ $set = $this->shortcutSetStorage->load($form_state->getValue('set')); $replacements = array( - '%user' => $this->user->getDisplayName(), + '%user' => $this->user->getAccountName(), '%set_name' => $set->label(), ); drupal_set_message($account_is_user ? $this->t('You are now using the %set_name shortcut set.', $replacements) : $this->t('%user is now using the %set_name shortcut set.', $replacements)); diff --git a/core/modules/user/config/install/user.mail.yml b/core/modules/user/config/install/user.mail.yml index cea80f6..358aa84 100644 --- a/core/modules/user/config/install/user.mail.yml +++ b/core/modules/user/config/install/user.mail.yml @@ -1,28 +1,28 @@ cancel_confirm: - body: "[user:display-name],\n\nA request to cancel your account has been made at [site:name].\n\nYou may now cancel your account on [site:url-brief] by clicking this link or copying and pasting it into your browser:\n\n[user:cancel-url]\n\nNOTE: The cancellation of your account is not reversible.\n\nThis link expires in one day and nothing will happen if it is not used.\n\n-- [site:name] team" - subject: 'Account cancellation request for [user:display-name] at [site:name]' + body: "[user:account-name],\n\nA request to cancel your account has been made at [site:name].\n\nYou may now cancel your account on [site:url-brief] by clicking this link or copying and pasting it into your browser:\n\n[user:cancel-url]\n\nNOTE: The cancellation of your account is not reversible.\n\nThis link expires in one day and nothing will happen if it is not used.\n\n-- [site:name] team" + subject: 'Account cancellation request for [user:account-name] at [site:name]' password_reset: - body: "[user:display-name],\n\nA request to reset the password for your account has been made at [site:name].\n\nYou may now log in by clicking this link or copying and pasting it to your browser:\n\n[user:one-time-login-url]\n\nThis link can only be used once to log in and will lead you to a page where you can set your password. It expires after one day and nothing will happen if it's not used.\n\n-- [site:name] team" - subject: 'Replacement login information for [user:display-name] at [site:name]' + body: "[user:account-name],\n\nA request to reset the password for your account has been made at [site:name].\n\nYou may now log in by clicking this link or copying and pasting it to your browser:\n\n[user:one-time-login-url]\n\nThis link can only be used once to log in and will lead you to a page where you can set your password. It expires after one day and nothing will happen if it's not used.\n\n-- [site:name] team" + subject: 'Replacement login information for [user:account-name] at [site:name]' register_admin_created: - body: "[user:display-name],\n\nA site administrator at [site:name] has created an account for you. You may now log in by clicking this link or copying and pasting it to your browser:\n\n[user:one-time-login-url]\n\nThis link can only be used once to log in and will lead you to a page where you can set your password.\n\nAfter setting your password, you will be able to log in at [site:login-url] in the future using:\n\nusername: [user:name]\npassword: Your password\n\n-- [site:name] team" + body: "[user:account-name],\n\nA site administrator at [site:name] has created an account for you. You may now log in by clicking this link or copying and pasting it to your browser:\n\n[user:one-time-login-url]\n\nThis link can only be used once to log in and will lead you to a page where you can set your password.\n\nAfter setting your password, you will be able to log in at [site:login-url] in the future using:\n\nusername: [user:name]\npassword: Your password\n\n-- [site:name] team" subject: 'An administrator created an account for you at [site:name]' register_no_approval_required: - body: "[user:display-name],\n\nThank you for registering at [site:name]. You may now log in by clicking this link or copying and pasting it to your browser:\n\n[user:one-time-login-url]\n\nThis link can only be used once to log in and will lead you to a page where you can set your password.\n\nAfter setting your password, you will be able to log in at [site:login-url] in the future using:\n\nusername: [user:name]\npassword: Your password\n\n-- [site:name] team" - subject: 'Account details for [user:display-name] at [site:name]' + body: "[user:account-name],\n\nThank you for registering at [site:name]. You may now log in by clicking this link or copying and pasting it to your browser:\n\n[user:one-time-login-url]\n\nThis link can only be used once to log in and will lead you to a page where you can set your password.\n\nAfter setting your password, you will be able to log in at [site:login-url] in the future using:\n\nusername: [user:name]\npassword: Your password\n\n-- [site:name] team" + subject: 'Account details for [user:account-name] at [site:name]' register_pending_approval: - body: "[user:display-name],\n\nThank you for registering at [site:name]. Your application for an account is currently pending approval. Once it has been approved, you will receive another email containing information about how to log in, set your password, and other details.\n\n\n-- [site:name] team" - subject: 'Account details for [user:display-name] at [site:name] (pending admin approval)' + body: "[user:account-name],\n\nThank you for registering at [site:name]. Your application for an account is currently pending approval. Once it has been approved, you will receive another email containing information about how to log in, set your password, and other details.\n\n\n-- [site:name] team" + subject: 'Account details for [user:account-name] at [site:name] (pending admin approval)' register_pending_approval_admin: - body: "[user:display-name] has applied for an account.\n\n[user:edit-url]" - subject: 'Account details for [user:display-name] at [site:name] (pending admin approval)' + body: "[user:account-name] has applied for an account.\n\n[user:edit-url]" + subject: 'Account details for [user:account-name] at [site:name] (pending admin approval)' status_activated: - body: "[user:display-name],\n\nYour account at [site:name] has been activated.\n\nYou may now log in by clicking this link or copying and pasting it into your browser:\n\n[user:one-time-login-url]\n\nThis link can only be used once to log in and will lead you to a page where you can set your password.\n\nAfter setting your password, you will be able to log in at [site:login-url] in the future using:\n\nusername: [user:name]\npassword: Your password\n\n-- [site:name] team" - subject: 'Account details for [user:display-name] at [site:name] (approved)' + body: "[user:account-name],\n\nYour account at [site:name] has been activated.\n\nYou may now log in by clicking this link or copying and pasting it into your browser:\n\n[user:one-time-login-url]\n\nThis link can only be used once to log in and will lead you to a page where you can set your password.\n\nAfter setting your password, you will be able to log in at [site:login-url] in the future using:\n\nusername: [user:name]\npassword: Your password\n\n-- [site:name] team" + subject: 'Account details for [user:account-name] at [site:name] (approved)' status_blocked: - body: "[user:name],\n\nYour account on [site:display-name] has been blocked.\n\n-- [site:name] team" - subject: 'Account details for [user:display-name] at [site:name] (blocked)' + body: "[user:name],\n\nYour account on [site:account-name] has been blocked.\n\n-- [site:name] team" + subject: 'Account details for [user:account-name] at [site:name] (blocked)' status_canceled: - body: "[user:display-name],\n\nYour account on [site:name] has been canceled.\n\n-- [site:name] team" - subject: 'Account details for [user:display-name] at [site:name] (canceled)' + body: "[user:account-name],\n\nYour account on [site:name] has been canceled.\n\n-- [site:name] team" + subject: 'Account details for [user:account-name] at [site:name] (canceled)' langcode: en diff --git a/core/modules/user/src/Plugin/Field/FieldFormatter/UserNameFormatter.php b/core/modules/user/src/Plugin/Field/FieldFormatter/UserNameFormatter.php index 1886ed9..e53168e 100644 --- a/core/modules/user/src/Plugin/Field/FieldFormatter/UserNameFormatter.php +++ b/core/modules/user/src/Plugin/Field/FieldFormatter/UserNameFormatter.php @@ -72,7 +72,7 @@ public function viewElements(FieldItemListInterface $items) { } else { $elements[$delta] = [ - '#markup' => $user->getDisplayName(), + '#markup' => $user->getAccountName(), '#cache' => [ 'tags' => $user->getCacheTags(), ], diff --git a/core/modules/user/src/Plugin/Search/UserSearch.php b/core/modules/user/src/Plugin/Search/UserSearch.php index a0fb3b4..e9e98fa 100644 --- a/core/modules/user/src/Plugin/Search/UserSearch.php +++ b/core/modules/user/src/Plugin/Search/UserSearch.php @@ -148,7 +148,7 @@ public function execute() { foreach ($accounts as $account) { $result = array( - 'title' => $account->getDisplayName(), + 'title' => $account->getAccountName(), 'link' => $account->url('canonical', array('absolute' => TRUE)), ); if ($this->currentUser->hasPermission('administer users')) { diff --git a/core/modules/user/src/Tests/Field/UserNameFormatterTest.php b/core/modules/user/src/Tests/Field/UserNameFormatterTest.php index fab8cd9..a70ac88 100644 --- a/core/modules/user/src/Tests/Field/UserNameFormatterTest.php +++ b/core/modules/user/src/Tests/Field/UserNameFormatterTest.php @@ -87,7 +87,7 @@ public function testFormatter() { $this->assertEqual(spl_object_hash($user), spl_object_hash($result[0]['#account'])); $result = $user->{$this->fieldName}->view(['type' => 'user_name', 'settings' => ['link_to_entity' => FALSE]]); - $this->assertEqual($user->getDisplayName(), $result[0]['#markup']); + $this->assertEqual($user->getAccountName(), $result[0]['#markup']); $user = User::getAnonymousUser(); @@ -96,7 +96,7 @@ public function testFormatter() { $this->assertEqual(spl_object_hash($user), spl_object_hash($result[0]['#account'])); $result = $user->{$this->fieldName}->view(['type' => 'user_name', 'settings' => ['link_to_entity' => FALSE]]); - $this->assertEqual($user->getDisplayName(), $result[0]['#markup']); + $this->assertEqual($user->getAccountName(), $result[0]['#markup']); $this->assertEqual($this->config('user.settings')->get('anonymous'), $result[0]['#markup']); } diff --git a/core/modules/user/src/Tests/UserCancelTest.php b/core/modules/user/src/Tests/UserCancelTest.php index 6597351..ba43c37 100644 --- a/core/modules/user/src/Tests/UserCancelTest.php +++ b/core/modules/user/src/Tests/UserCancelTest.php @@ -367,7 +367,7 @@ function testUserAnonymize() { $storage->resetCache(array($comment->id())); $test_comment = $storage->load($comment->id()); $this->assertTrue(($test_comment->getOwnerId() == 0 && $test_comment->isPublished()), 'Comment of the user has been attributed to anonymous user.'); - $this->assertEqual($test_comment->getAuthorName(), $anonymous_user->getDisplayName(), 'Comment of the user has been attributed to anonymous user name.'); + $this->assertEqual($test_comment->getAuthorName(), $anonymous_user->getAccountName(), '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.', array('%name' => $account->getUsername())), "Confirmation message displayed to user."); diff --git a/core/modules/user/src/Tests/UserEntityCallbacksTest.php b/core/modules/user/src/Tests/UserEntityCallbacksTest.php index cec3502..b3a9bad 100644 --- a/core/modules/user/src/Tests/UserEntityCallbacksTest.php +++ b/core/modules/user/src/Tests/UserEntityCallbacksTest.php @@ -55,13 +55,13 @@ function testLabelCallback() { $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->getAccountName(), $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'); // Set to test the altered username. \Drupal::state()->set('user_name_test_altered_name', 'altered'); - $this->assertEqual($this->account->getDisplayName(), $this->account->name->value . 'altered', 'The user display name should be altered.'); + $this->assertEqual($this->account->getAccountName(), $this->account->name->value . 'altered', 'The user display name should be altered.'); $this->assertEqual($this->account->getUsername(), $this->account->name->value, 'The user name should not be altered.'); } diff --git a/core/modules/user/src/Tests/UserTokenReplaceTest.php b/core/modules/user/src/Tests/UserTokenReplaceTest.php index 5b5782d..1544eab 100644 --- a/core/modules/user/src/Tests/UserTokenReplaceTest.php +++ b/core/modules/user/src/Tests/UserTokenReplaceTest.php @@ -60,7 +60,7 @@ function testUserTokenReplacement() { // Generate and test sanitized tokens. $tests = array(); $tests['[user:uid]'] = $account->id(); - $tests['[user:display-name]'] = Html::escape($account->getDisplayName()); + $tests['[user:account-name]'] = Html::escape($account->getAccountName()); $tests['[user:name]'] = Html::escape($account->getUsername()); $tests['[user:mail]'] = Html::escape($account->getEmail()); $tests['[user:url]'] = $account->url('canonical', $url_options); @@ -69,14 +69,14 @@ function testUserTokenReplacement() { $tests['[user:last-login:short]'] = format_date($account->getLastLoginTime(), 'short', '', NULL, $language_interface->getId()); $tests['[user:created]'] = format_date($account->getCreatedTime(), 'medium', '', NULL, $language_interface->getId()); $tests['[user:created:short]'] = format_date($account->getCreatedTime(), 'short', '', NULL, $language_interface->getId()); - $tests['[current-user:display-name]'] = Html::escape($global_account->getDisplayName()); + $tests['[current-user:account-name]'] = Html::escape($global_account->getAccountName()); $tests['[current-user:name]'] = Html::escape($global_account->getUsername()); $base_bubbleable_metadata = BubbleableMetadata::createFromObject($account); $metadata_tests = []; $metadata_tests['[user:uid]'] = $base_bubbleable_metadata; $metadata_tests['[user:name]'] = $base_bubbleable_metadata; - $metadata_tests['[user:display-name]'] = $base_bubbleable_metadata; + $metadata_tests['[user:account-name]'] = $base_bubbleable_metadata; $metadata_tests['[user:mail]'] = $base_bubbleable_metadata; $metadata_tests['[user:url]'] = $base_bubbleable_metadata; $metadata_tests['[user:edit-url]'] = $base_bubbleable_metadata; @@ -92,7 +92,7 @@ function testUserTokenReplacement() { $metadata_tests['[user:created]'] = $bubbleable_metadata; $metadata_tests['[user:created:short]'] = $bubbleable_metadata; $metadata_tests['[current-user:name]'] = $base_bubbleable_metadata->merge(BubbleableMetadata::createFromObject($global_account)->addCacheContexts(['user'])); - $metadata_tests['[current-user:display-name]'] = $base_bubbleable_metadata->merge(BubbleableMetadata::createFromObject($global_account)->addCacheContexts(['user'])); + $metadata_tests['[current-user:account-name]'] = $base_bubbleable_metadata->merge(BubbleableMetadata::createFromObject($global_account)->addCacheContexts(['user'])); // Test to make sure that we generated something for each token. $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); @@ -108,14 +108,14 @@ function testUserTokenReplacement() { $anonymous_user = User::load(0); $tests = []; $tests['[user:uid]'] = t('not yet assigned'); - $tests['[user:display-name]'] = Html::escape(user_format_name($anonymous_user)); + $tests['[user:account-name]'] = Html::escape(user_format_name($anonymous_user)); $base_bubbleable_metadata = BubbleableMetadata::createFromObject($anonymous_user); $metadata_tests = []; $metadata_tests['[user:uid]'] = $base_bubbleable_metadata; $bubbleable_metadata = clone $base_bubbleable_metadata; $bubbleable_metadata->addCacheableDependency(\Drupal::config('user.settings')); - $metadata_tests['[user:display-name]'] = $bubbleable_metadata; + $metadata_tests['[user:account-name]'] = $bubbleable_metadata; foreach ($tests as $input => $expected) { $bubbleable_metadata = new BubbleableMetadata(); @@ -126,10 +126,10 @@ function testUserTokenReplacement() { // Generate and test unsanitized tokens. $tests = []; - $tests['[user:display-name]'] = $account->getDisplayName(); + $tests['[user:account-name]'] = $account->getAccountName(); $tests['[user:name]'] = $account->getUsername(); $tests['[user:mail]'] = $account->getEmail(); - $tests['[current-user:display-name]'] = $global_account->getDisplayName(); + $tests['[current-user:account-name]'] = $global_account->getAccountName(); $tests['[current-user:name]'] = $global_account->getUsername(); foreach ($tests as $input => $expected) { diff --git a/core/modules/user/src/Tests/Views/HandlerFieldUserNameTest.php b/core/modules/user/src/Tests/Views/HandlerFieldUserNameTest.php index d752157..1b67878 100644 --- a/core/modules/user/src/Tests/Views/HandlerFieldUserNameTest.php +++ b/core/modules/user/src/Tests/Views/HandlerFieldUserNameTest.php @@ -52,7 +52,7 @@ public function testUserName() { $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view, $new_user) { return $view->field['name']->advancedRender($view->result[$new_user->id()]); }); - $this->assertTrue(strpos($render, $new_user->getDisplayName()) !== FALSE, 'If link to user is checked the username should be part of the output.'); + $this->assertTrue(strpos($render, $new_user->getAccountName()) !== FALSE, 'If link to user is checked the username should be part of the output.'); $this->assertTrue(strpos($render, 'user/' . $new_user->id()) !== FALSE, 'If link to user is checked the link to the user should appear as well.'); $view->field['name']->options['link_to_user'] = FALSE; @@ -60,7 +60,7 @@ public function testUserName() { $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view, $new_user) { return $view->field['name']->advancedRender($view->result[$new_user->id()]); }); - $this->assertEqual($render, $new_user->getDisplayName(), 'If the user is not linked the username should be printed out for a normal user.'); + $this->assertEqual($render, $new_user->getAccountName(), 'If the user is not linked the username should be printed out for a normal user.'); } diff --git a/core/modules/user/user.api.php b/core/modules/user/user.api.php index c2e5ae2..89b6afa 100644 --- a/core/modules/user/user.api.php +++ b/core/modules/user/user.api.php @@ -107,17 +107,17 @@ function hook_user_cancel_methods_alter(&$methods) { /** * Alter the username that is displayed for a user. * - * Called by $user->getDisplayName() to allow modules to alter the username that's + * Called by $user->getAccountName() to allow modules to alter the username that's * displayed. Can be used to ensure user privacy in situations where * $account->name is too revealing. * * @param string $name - * The string that $user->getDisplayName() will return. + * The string that $user->getAccountName() will return. * * @param $account * The account object passed to user_format_name(). * - * @see $account->getDisplayName() + * @see $account->getAccountName() */ function hook_user_format_name_alter(&$name, $account) { // Display the user's uid instead of name. diff --git a/core/modules/user/user.module b/core/modules/user/user.module index c133fe7..80c8ea6 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -418,10 +418,10 @@ function user_preprocess_block(&$variables) { * is called on it before it is printed to the page. * * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. - * Use \Drupal\Core\Session\AccountInterface::getDisplayName(). + * Use \Drupal\Core\Session\AccountInterface::getAccountName(). */ function user_format_name(AccountInterface $account) { - return $account->getDisplayName(); + return $account->getAccountName(); } /** @@ -471,7 +471,7 @@ function template_preprocess_username(&$variables) { // unsanitized version, in case other preprocess functions want to implement // their own shortening logic or add markup. If they do so, they must ensure // that $variables['name'] is safe for printing. - $name = $account->getDisplayName(); + $name = $account->getAccountName(); $variables['name_raw'] = $account->getUsername(); if (Unicode::strlen($name) > 20) { $name = Unicode::truncate($name, 15, FALSE, TRUE); @@ -741,8 +741,8 @@ function _user_cancel($edit, $account, $method) { } $account->block(); $account->save(); - drupal_set_message(t('%name has been disabled.', array('%name' => $account->getDisplayName()))); - $logger->notice('Blocked user: %name %email.', array('%name' => $account->getDisplayName(), '%email' => '<' . $account->getEmail() . '>')); + drupal_set_message(t('%name has been disabled.', array('%name' => $account->getAccountName()))); + $logger->notice('Blocked user: %name %email.', array('%name' => $account->getAccountName(), '%email' => '<' . $account->getEmail() . '>')); break; case 'user_cancel_reassign': @@ -752,8 +752,8 @@ function _user_cancel($edit, $account, $method) { _user_mail_notify('status_canceled', $account); } $account->delete(); - drupal_set_message(t('%name has been deleted.', array('%name' => $account->getDisplayName()))); - $logger->notice('Deleted user: %name %email.', array('%name' => $account->getDisplayName(), '%email' => '<' . $account->getEmail() . '>')); + drupal_set_message(t('%name has been deleted.', array('%name' => $account->getAccountName()))); + $logger->notice('Deleted user: %name %email.', array('%name' => $account->getAccountName(), '%email' => '<' . $account->getEmail() . '>')); break; } @@ -1365,7 +1365,7 @@ function user_toolbar() { '#type' => 'toolbar_item', 'tab' => array( '#type' => 'link', - '#title' => $user->getDisplayName(), + '#title' => $user->getAccountName(), '#url' => Url::fromRoute('user.page'), '#attributes' => array( 'title' => t('My account'), @@ -1410,7 +1410,7 @@ function user_toolbar() { function user_logout() { $user = \Drupal::currentUser(); - \Drupal::logger('user')->notice('Session closed for %name.', array('%name' => $user->getDisplayName())); + \Drupal::logger('user')->notice('Session closed for %name.', array('%name' => $user->getAccountName())); \Drupal::moduleHandler()->invokeAll('user_logout', array($user)); diff --git a/core/modules/user/user.tokens.inc b/core/modules/user/user.tokens.inc index a638ac0..a174f9b 100644 --- a/core/modules/user/user.tokens.inc +++ b/core/modules/user/user.tokens.inc @@ -33,8 +33,8 @@ function user_token_info() { 'name' => t("Display Name"), 'description' => t("The display name of the user account."), ); - $user['display-name'] = array( - 'name' => t("Login Name"), + $user['account-name'] = array( + 'name' => t("Account Name"), 'description' => t("The login name of the user account."), ); $user['mail'] = array( @@ -103,8 +103,8 @@ function user_tokens($type, $tokens, array $data, array $options, BubbleableMeta $bubbleable_metadata->addCacheableDependency(\Drupal::config('user.settings')); } break; - case 'display-name': - $display_name = $account->getDisplayName(); + case 'account-name': + $display_name = $account->getAccountName(); $replacements[$original] = $sanitize ? Html::escape($display_name) : $display_name; if ($account->isAnonymous()) { $bubbleable_metadata->addCacheableDependency(\Drupal::config('user.settings'));