function _token_example_get_comment in Examples for Developers 7
Same name and namespace in other branches
- 6 token_example/token_example.module \_token_example_get_comment()
Builds a list of available comments.
Related topics
File
- token_example/
token_example.module, line 165 - An example module showing how to define and use tokens.
Code
function _token_example_get_comment() {
if (!module_exists('comment') || !user_access('access comments') && !user_access('administer comments')) {
return array();
}
$comment_query = db_select('comment', 'c');
$comment_query
->innerJoin('node', 'n', 'n.nid = c.nid');
$comment_query
->fields('c', array(
'cid',
'subject',
));
$comment_query
->condition('n.status', NODE_PUBLISHED);
$comment_query
->condition('c.status', COMMENT_PUBLISHED);
$comment_query
->orderBy('c.created', 'DESC');
$comment_query
->range(0, 10);
$comment_query
->addTag('node_access');
$comments = $comment_query
->execute()
->fetchAllKeyed();
$comments = array_map('check_plain', $comments);
return $comments;
}