1 comment.module | comment_node_update_index(Node $node) |
Implements hook_node_update_index().
File
- core/
modules/ comment/ comment.module, line 1367 - Enables users to comment on published content.
Code
function comment_node_update_index(Node $node) {
$index_comments = &backdrop_static(__FUNCTION__);
if ($index_comments === NULL) {
// Find and save roles that can 'access comments' or 'search content'.
$perms = array(
'access comments' => array(),
'search content' => array(),
);
$roles = user_roles(FALSE, NULL, TRUE);
foreach ($roles as $role_name => $role) {
if (in_array('access comments', $role->permissions)) {
$perms['access comments'][$role_name] = $role_name;
}
if (in_array('search content', $role->permissions)) {
$perms['search content'][$role_name] = $role_name;
}
}
// Prevent indexing of comments if there are any roles that can search but
// not view comments.
$index_comments = TRUE;
foreach ($perms['search content'] as $role_name) {
if (!isset($perms['access comments'][$role_name]) && ($role_name === BACKDROP_ANONYMOUS_ROLE || $role_name === BACKDROP_AUTHENTICATED_ROLE || !isset($perms['access comments'][BACKDROP_AUTHENTICATED_ROLE]))) {
$index_comments = FALSE;
break;
}
}
}
if ($index_comments) {
$node_type = node_type_get_type($node->type);
$mode = $node_type->settings['comment_mode'];
$comments_per_page = $node_type->settings['comment_per_page'];
if ($node->comment && $cids = comment_get_thread($node, $mode, $comments_per_page)) {
$comments = comment_load_multiple($cids);
if ($comments) {
comment_prepare_thread($comments);
$build = comment_view_multiple($comments, $node);
return backdrop_render($build);
}
}
}
return '';
}