diff --git a/core/modules/user/src/Plugin/views/field/Name.php b/core/modules/user/src/Plugin/views/field/Name.php index 2167db4..4f46a50 100644 --- a/core/modules/user/src/Plugin/views/field/Name.php +++ b/core/modules/user/src/Plugin/views/field/Name.php @@ -23,18 +23,8 @@ class Name extends User { /** - * Overrides \Drupal\user\Plugin\views\field\User::init(). - * - * Add uid in the query so we can test for anonymous if needed. + * {@inheritdoc} */ - public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { - parent::init($view, $display, $options); - - if (!empty($this->options['overwrite_anonymous']) || !empty($this->options['format_username'])) { - $this->additional_fields['uid'] = 'uid'; - } - } - protected function defineOptions() { $options = parent::defineOptions(); @@ -79,23 +69,26 @@ public function buildOptionsForm(&$form, &$form_state) { * {@inheritdoc} */ protected function renderLink($data, ResultRow $values) { - $account = entity_create('user'); - $account->uid = $this->getValue($values, 'uid'); - $account->name = $this->getValue($values); - if (!empty($this->options['link_to_user']) || !empty($this->options['overwrite_anonymous'])) { - if (!empty($this->options['overwrite_anonymous']) && !$account->id()) { - // This is an anonymous user, and we're overriting the text. - return String::checkPlain($this->options['anonymous_text']); - } - elseif (!empty($this->options['link_to_user'])) { - $account->name = $this->getValue($values); + $account = $this->getEntity($values); + + if (!empty($this->options['overwrite_anonymous']) && !$account->id()) { + // This is an anonymous user, and we're overwriting the text. + return String::checkPlain($this->options['anonymous_text']); + } + + if (!empty($this->options['link_to_user'])) { + if (!empty($this->options['format_username'])) { $username = array( '#theme' => 'username', '#account' => $account, ); return drupal_render($username); } + else { + return parent::renderLink($data, $values); + } } + // If we want a formatted username, do that. if (!empty($this->options['format_username'])) { return $account->getDisplayName();