diff --git a/core/modules/comment/config/schema/comment.views.schema.yml b/core/modules/comment/config/schema/comment.views.schema.yml index 51953ad..cdb22cf 100644 --- a/core/modules/comment/config/schema/comment.views.schema.yml +++ b/core/modules/comment/config/schema/comment.views.schema.yml @@ -78,14 +78,6 @@ views.field.comment_ces_last_updated: type: views_field label: 'Newer of last comment / node updated' -views.field.comment_username: - type: views_field - label: 'Node comment status' - mapping: - link_to_user: - type: boolean - label: 'Link this field to its user or an author''s homepage' - views.filter.node_comment: type: views.filter.in_operator label: 'Comment node status' diff --git a/core/modules/comment/src/CommentViewsData.php b/core/modules/comment/src/CommentViewsData.php index f84e221..e8c4a7a 100644 --- a/core/modules/comment/src/CommentViewsData.php +++ b/core/modules/comment/src/CommentViewsData.php @@ -33,7 +33,8 @@ public function getViewsData() { $data['comment_field_data']['name']['title'] = t('Author'); $data['comment_field_data']['name']['help'] = t("The name of the comment's author. Can be rendered as a link to the author's homepage."); - $data['comment_field_data']['name']['field']['id'] = 'comment_username'; + $data['comment_field_data']['name']['field']['id'] = 'field'; + $data['comment_field_data']['name']['field']['default_formatter'] = 'comment_username'; $data['comment_field_data']['homepage']['title'] = t("Author's website"); $data['comment_field_data']['homepage']['help'] = t("The website address of the comment's author. Can be rendered as a link. Will be empty if the author is a registered user."); diff --git a/core/modules/comment/src/Plugin/Field/FieldFormatter/AuthorNameFormatter.php b/core/modules/comment/src/Plugin/Field/FieldFormatter/AuthorNameFormatter.php new file mode 100644 index 0000000..a74628f --- /dev/null +++ b/core/modules/comment/src/Plugin/Field/FieldFormatter/AuthorNameFormatter.php @@ -0,0 +1,50 @@ + $item) { + /** @var $comment \Drupal\comment\CommentInterface */ + $comment = $item->getEntity(); + $account = $comment->getOwner(); + if ($account->isAnonymous()) { + $account->setUsername($comment->getAuthorName()); + $account->setEmail($comment->getAuthorEmail()); + $account->homepage = $comment->getHomepage(); + } + $elements[$delta] = array( + '#theme' => 'username', + '#account' => $account, + ); + } + + return $elements; + } +} diff --git a/core/modules/comment/src/Plugin/views/field/Username.php b/core/modules/comment/src/Plugin/views/field/Username.php deleted file mode 100644 index c82a301..0000000 --- a/core/modules/comment/src/Plugin/views/field/Username.php +++ /dev/null @@ -1,94 +0,0 @@ -additional_fields['uid'] = 'uid'; - $this->additional_fields['homepage'] = 'homepage'; - } - - /** - * {@inheritdoc} - */ - protected function defineOptions() { - $options = parent::defineOptions(); - $options['link_to_user'] = array('default' => TRUE); - return $options; - } - - /** - * {@inheritdoc} - */ - public function buildOptionsForm(&$form, FormStateInterface $form_state) { - $form['link_to_user'] = array( - '#title' => $this->t("Link this field to its user or an author's homepage"), - '#type' => 'checkbox', - '#default_value' => $this->options['link_to_user'], - ); - parent::buildOptionsForm($form, $form_state); - } - - /** - * Prepares link for the comment's author. - * - * @param string $data - * The XSS safe string for the link text. - * @param \Drupal\views\ResultRow $values - * The values retrieved from a single row of a view's query result. - * - * @return string - * Returns a string for the link text. - */ - protected function renderLink($data, ResultRow $values) { - if (!empty($this->options['link_to_user'])) { - $account = entity_create('user'); - $account->uid = $this->getValue($values, 'uid'); - $account->name = $this->getValue($values); - $account->homepage = $this->getValue($values, 'homepage'); - $username = array( - '#theme' => 'username', - '#account' => $account, - ); - return drupal_render($username); - } - else { - return $data; - } - } - - /** - * {@inheritdoc} - */ - public function render(ResultRow $values) { - $value = $this->getValue($values); - return $this->renderLink($this->sanitizeValue($value), $values); - } - -} diff --git a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rest.yml b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rest.yml index 0c53369..d55c8f3 100644 --- a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rest.yml +++ b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rest.yml @@ -193,8 +193,8 @@ display: hide_empty: false empty_zero: false hide_alter_empty: true - link_to_user: false - plugin_id: comment_username + plugin_id: field + type: comment_username created: id: created table: comment_field_data