function NodeNewComments::renderLink
Same name in other branches
- 9 core/modules/comment/src/Plugin/views/field/NodeNewComments.php \Drupal\comment\Plugin\views\field\NodeNewComments::renderLink()
- 10 core/modules/comment/src/Plugin/views/field/NodeNewComments.php \Drupal\comment\Plugin\views\field\NodeNewComments::renderLink()
- 11.x core/modules/comment/src/Plugin/views/field/NodeNewComments.php \Drupal\comment\Plugin\views\field\NodeNewComments::renderLink()
Prepares the link to the first new comment.
Parameters
string $data: The XSS safe string for the link text.
\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.
Return value
string Returns a string for the link text.
1 call to NodeNewComments::renderLink()
- NodeNewComments::render in core/
modules/ comment/ src/ Plugin/ views/ field/ NodeNewComments.php - Renders the field.
File
-
core/
modules/ comment/ src/ Plugin/ views/ field/ NodeNewComments.php, line 194
Class
- NodeNewComments
- Field handler to display the number of new comments.
Namespace
Drupal\comment\Plugin\views\fieldCode
protected function renderLink($data, ResultRow $values) {
if (!empty($this->options['link_to_comment']) && $data !== NULL && $data !== '') {
$node_type = $this->getValue($values, 'type');
$node = Node::create([
'nid' => $this->getValue($values, 'nid'),
'type' => $node_type,
]);
// Because there is no support for selecting a specific comment field to
// reference, we arbitrarily use the first such field name we find.
// @todo Provide a means for selecting the comment field.
// https://www.drupal.org/node/2594201
$field_map = $this->entityFieldManager
->getFieldMapByFieldType('comment');
$comment_field_name = 'comment';
foreach ($field_map['node'] as $field_name => $field_data) {
foreach ($field_data['bundles'] as $bundle_name) {
if ($node_type == $bundle_name) {
$comment_field_name = $field_name;
break 2;
}
}
}
$page_number = $this->entityTypeManager
->getStorage('comment')
->getNewCommentPageNumber($this->getValue($values, 'comment_count'), $this->getValue($values), $node, $comment_field_name);
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['url'] = $node->toUrl();
$this->options['alter']['query'] = $page_number ? [
'page' => $page_number,
] : NULL;
$this->options['alter']['fragment'] = 'new';
}
return $data;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.