2009-05-17 11:16:51 +00:00
< ? php
/**
* @ file
* Provide views data and handlers for comment . module .
*
* @ ingroup views_module_handlers
*/
/**
* Implements hook_views_data () .
*/
function comment_views_data () {
// Define the base group of this table. Fields that don't
// have a group defined will go into this field by default.
$data [ 'comment' ][ 'table' ][ 'group' ] = t ( 'Comment' );
$data [ 'comment' ][ 'table' ][ 'base' ] = array (
'field' => 'cid' ,
'title' => t ( 'Comment' ),
'help' => t ( " Comments are responses to node content. " ),
'access query tag' => 'comment_access' ,
);
$data [ 'comment' ][ 'table' ][ 'entity type' ] = 'comment' ;
2012-11-29 06:20:24 +00:00
$data [ 'comment' ][ 'table' ][ 'wizard_id' ] = 'comment' ;
2009-05-17 11:16:51 +00:00
// Fields
// subject
$data [ 'comment' ][ 'subject' ] = array (
'title' => t ( 'Title' ),
'help' => t ( 'The title of the comment.' ),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'comment' ,
2009-05-17 11:16:51 +00:00
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'string' ,
2009-05-17 11:16:51 +00:00
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
'argument' => array (
2012-08-11 11:46:07 +00:00
'id' => 'string' ,
2009-05-17 11:16:51 +00:00
),
);
// cid
$data [ 'comment' ][ 'cid' ] = array (
'title' => t ( 'ID' ),
'help' => t ( 'The comment ID of the field' ),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'comment' ,
2009-05-17 11:16:51 +00:00
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'numeric' ,
2009-05-17 11:16:51 +00:00
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
'argument' => array (
2012-08-11 11:46:07 +00:00
'id' => 'numeric' ,
2009-05-17 11:16:51 +00:00
),
);
// name (of comment author)
$data [ 'comment' ][ 'name' ] = array (
'title' => t ( 'Author' ),
'help' => t ( " The name of the comment's author. Can be rendered as a link to the author's homepage. " ),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'comment_username' ,
2009-05-17 11:16:51 +00:00
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'string' ,
2009-05-17 11:16:51 +00:00
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
'argument' => array (
2012-08-11 11:46:07 +00:00
'id' => 'string' ,
2009-05-17 11:16:51 +00:00
),
);
// homepage
$data [ 'comment' ][ 'homepage' ] = array (
'title' => t ( " Author's website " ),
'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. " ),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'url' ,
2009-05-17 11:16:51 +00:00
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'string' ,
2009-05-17 11:16:51 +00:00
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
'argument' => array (
2012-08-11 11:46:07 +00:00
'id' => 'string' ,
2009-05-17 11:16:51 +00:00
),
);
// hostname
$data [ 'comment' ][ 'hostname' ] = array (
'title' => t ( 'Hostname' ),
'help' => t ( 'Hostname of user that posted the comment.' ),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'string' ,
2009-05-17 11:16:51 +00:00
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
'argument' => array (
2012-08-11 11:46:07 +00:00
'id' => 'string' ,
2009-05-17 11:16:51 +00:00
),
);
// mail
$data [ 'comment' ][ 'mail' ] = array (
'title' => t ( 'Mail' ),
'help' => t ( 'Email of user that posted the comment. Will be empty if the author is a registered user.' ),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'string' ,
2009-05-17 11:16:51 +00:00
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
'argument' => array (
2012-08-11 11:46:07 +00:00
'id' => 'string' ,
2009-05-17 11:16:51 +00:00
),
);
// created (when comment was posted)
$data [ 'comment' ][ 'created' ] = array (
'title' => t ( 'Post date' ),
'help' => t ( 'Date and time of when the comment was created.' ),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'date' ,
2009-05-17 11:16:51 +00:00
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'date' ,
2009-05-17 11:16:51 +00:00
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'date' ,
2009-05-17 11:16:51 +00:00
),
);
2012-08-26 19:44:59 +00:00
// Langcode field
if ( module_exists ( 'language' )) {
$data [ 'comment' ][ 'langcode' ] = array (
2012-05-31 19:21:44 +00:00
'title' => t ( 'Language' ),
'help' => t ( 'The language the comment is in.' ),
'field' => array (
2012-09-12 22:26:07 +00:00
'id' => 'language' ,
2012-05-31 19:21:44 +00:00
),
'filter' => array (
2012-09-12 22:26:07 +00:00
'id' => 'language' ,
2012-05-31 19:21:44 +00:00
),
'argument' => array (
2012-09-12 22:26:07 +00:00
'id' => 'language' ,
2012-05-31 19:21:44 +00:00
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2012-05-31 19:21:44 +00:00
),
);
}
2009-05-17 11:16:51 +00:00
// changed (when comment was last updated)
$data [ 'comment' ][ 'changed' ] = array (
'title' => t ( 'Updated date' ),
'help' => t ( 'Date and time of when the comment was last updated.' ),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'date' ,
2009-05-17 11:16:51 +00:00
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'date' ,
2009-05-17 11:16:51 +00:00
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'date' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'comment' ][ 'changed_fulldata' ] = array (
'title' => t ( 'Created date' ),
'help' => t ( 'Date in the form of CCYYMMDD.' ),
'argument' => array (
'field' => 'changed' ,
2012-08-11 11:46:07 +00:00
'id' => 'node_created_fulldate' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'comment' ][ 'changed_year_month' ] = array (
'title' => t ( 'Created year + month' ),
'help' => t ( 'Date in the form of YYYYMM.' ),
'argument' => array (
'field' => 'changed' ,
2012-08-11 11:46:07 +00:00
'id' => 'node_created_year_month' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'comment' ][ 'changed_year' ] = array (
'title' => t ( 'Created year' ),
'help' => t ( 'Date in the form of YYYY.' ),
'argument' => array (
'field' => 'changed' ,
2012-08-11 11:46:07 +00:00
'id' => 'node_created_year' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'comment' ][ 'changed_month' ] = array (
'title' => t ( 'Created month' ),
'help' => t ( 'Date in the form of MM (01 - 12).' ),
'argument' => array (
'field' => 'changed' ,
2012-08-11 11:46:07 +00:00
'id' => 'node_created_month' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'comment' ][ 'changed_day' ] = array (
'title' => t ( 'Created day' ),
'help' => t ( 'Date in the form of DD (01 - 31).' ),
'argument' => array (
'field' => 'changed' ,
2012-08-11 11:46:07 +00:00
'id' => 'node_created_day' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'comment' ][ 'changed_week' ] = array (
'title' => t ( 'Created week' ),
'help' => t ( 'Date in the form of WW (01 - 53).' ),
'argument' => array (
'field' => 'changed' ,
2012-08-11 11:46:07 +00:00
'id' => 'node_created_week' ,
2009-05-17 11:16:51 +00:00
),
);
// status (approved or not)
$data [ 'comment' ][ 'status' ] = array (
'title' => t ( 'Approved' ),
'help' => t ( 'Whether the comment is approved (or still in the moderation queue).' ),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'boolean' ,
2009-05-17 11:16:51 +00:00
'output formats' => array (
'approved-not-approved' => array ( t ( 'Approved' ), t ( 'Not Approved' )),
),
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'boolean' ,
2009-05-17 11:16:51 +00:00
'label' => t ( 'Approved comment' ),
'type' => 'yes-no' ,
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
);
// link to view comment
$data [ 'comment' ][ 'view_comment' ] = array (
'field' => array (
'title' => t ( 'View link' ),
'help' => t ( 'Provide a simple link to view the comment.' ),
2012-08-11 11:46:07 +00:00
'id' => 'comment_link' ,
2009-05-17 11:16:51 +00:00
),
);
// link to edit comment
$data [ 'comment' ][ 'edit_comment' ] = array (
'field' => array (
'title' => t ( 'Edit link' ),
'help' => t ( 'Provide a simple link to edit the comment.' ),
2012-08-11 11:46:07 +00:00
'id' => 'comment_link_edit' ,
2009-05-17 11:16:51 +00:00
),
);
// link to delete comment
$data [ 'comment' ][ 'delete_comment' ] = array (
'field' => array (
'title' => t ( 'Delete link' ),
'help' => t ( 'Provide a simple link to delete the comment.' ),
2012-08-11 11:46:07 +00:00
'id' => 'comment_link_delete' ,
2009-05-17 11:16:51 +00:00
),
);
// link to approve comment
$data [ 'comment' ][ 'approve_comment' ] = array (
'field' => array (
'title' => t ( 'Approve link' ),
'help' => t ( 'Provide a simple link to approve the comment.' ),
2012-08-11 11:46:07 +00:00
'id' => 'comment_link_approve' ,
2009-05-17 11:16:51 +00:00
),
);
// link to reply to comment
$data [ 'comment' ][ 'replyto_comment' ] = array (
'field' => array (
'title' => t ( 'Reply-to link' ),
'help' => t ( 'Provide a simple link to reply to the comment.' ),
2012-08-11 11:46:07 +00:00
'id' => 'comment_link_reply' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'comment' ][ 'thread' ] = array (
'field' => array (
'title' => t ( 'Depth' ),
'help' => t ( 'Display the depth of the comment if it is threaded.' ),
2012-08-11 11:46:07 +00:00
'id' => 'comment_depth' ,
2009-05-17 11:16:51 +00:00
),
'sort' => array (
'title' => t ( 'Thread' ),
'help' => t ( 'Sort by the threaded order. This will keep child comments together with their parents.' ),
2012-08-11 11:46:07 +00:00
'id' => 'comment_thread' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'comment' ][ 'nid' ] = array (
'title' => t ( 'Nid' ),
'help' => t ( 'The node ID to which the comment is a reply to.' ),
'relationship' => array (
'title' => t ( 'Content' ),
'help' => t ( 'The content to which the comment is a reply to.' ),
'base' => 'node' ,
'base field' => 'nid' ,
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
'label' => t ( 'Content' ),
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'numeric' ,
2009-05-17 11:16:51 +00:00
),
'argument' => array (
2012-08-11 11:46:07 +00:00
'id' => 'numeric' ,
2009-05-17 11:16:51 +00:00
),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'numeric' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'comment' ][ 'uid' ] = array (
'title' => t ( 'Author uid' ),
'help' => t ( 'If you need more fields than the uid add the comment: author relationship' ),
'relationship' => array (
'title' => t ( 'Author' ),
'help' => t ( " The User ID of the comment's author. " ),
'base' => 'users' ,
'base field' => 'uid' ,
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
'label' => t ( 'author' ),
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'numeric' ,
2009-05-17 11:16:51 +00:00
),
'argument' => array (
2012-08-11 11:46:07 +00:00
'id' => 'numeric' ,
2009-05-17 11:16:51 +00:00
),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'user' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'comment' ][ 'pid' ] = array (
'title' => t ( 'Parent CID' ),
'help' => t ( 'The Comment ID of the parent comment.' ),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
'relationship' => array (
'title' => t ( 'Parent comment' ),
'help' => t ( 'The parent comment.' ),
'base' => 'comment' ,
'base field' => 'cid' ,
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
'label' => t ( 'Parent comment' ),
),
);
2013-01-25 20:32:06 +00:00
// Entity translation field.
if ( drupal_container () -> get ( 'module_handler' ) -> moduleExists ( 'translation_entity' )) {
$data [ 'comment' ][ 'translation_link' ] = array (
'title' => t ( 'Translation link' ),
'help' => t ( 'Provide a link to the translations overview for comments.' ),
'field' => array (
'id' => 'translation_entity_link' ,
),
);
}
2009-05-17 11:16:51 +00:00
// node_comment_statistics table
// define the group
$data [ 'node_comment_statistics' ][ 'table' ][ 'group' ] = t ( 'Content' );
// joins
$data [ 'node_comment_statistics' ][ 'table' ][ 'join' ] = array (
//...to the node table
'node' => array (
'type' => 'INNER' ,
'left_field' => 'nid' ,
'field' => 'nid' ,
),
);
// last_comment_timestamp
$data [ 'node_comment_statistics' ][ 'last_comment_timestamp' ] = array (
'title' => t ( 'Last comment time' ),
'help' => t ( 'Date and time of when the last comment was posted.' ),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'comment_last_timestamp' ,
2009-05-17 11:16:51 +00:00
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'date' ,
2009-05-17 11:16:51 +00:00
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'date' ,
2009-05-17 11:16:51 +00:00
),
);
// last_comment_name (author's name)
$data [ 'node_comment_statistics' ][ 'last_comment_name' ] = array (
'title' => t ( " Last comment author " ),
'help' => t ( 'The name of the author of the last posted comment.' ),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'comment_ncs_last_comment_name' ,
2009-05-17 11:16:51 +00:00
'no group by' => TRUE ,
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'comment_ncs_last_comment_name' ,
2009-05-17 11:16:51 +00:00
'no group by' => TRUE ,
),
);
// comment_count
$data [ 'node_comment_statistics' ][ 'comment_count' ] = array (
'title' => t ( 'Comment count' ),
'help' => t ( 'The number of comments a node has.' ),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'numeric' ,
2009-05-17 11:16:51 +00:00
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'numeric' ,
2009-05-17 11:16:51 +00:00
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
'argument' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
);
// last_comment_timestamp
$data [ 'node_comment_statistics' ][ 'last_updated' ] = array (
'title' => t ( 'Updated/commented date' ),
'help' => t ( 'The most recent of last comment posted or node updated time.' ),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'comment_ncs_last_updated' ,
2009-05-17 11:16:51 +00:00
'no group by' => TRUE ,
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'comment_ncs_last_updated' ,
2009-05-17 11:16:51 +00:00
'no group by' => TRUE ,
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'comment_ncs_last_updated' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'node_comment_statistics' ][ 'cid' ] = array (
'title' => t ( 'Last comment CID' ),
'help' => t ( 'Display the last comment of a node' ),
'relationship' => array (
'title' => t ( 'Last Comment' ),
'help' => t ( 'The last comment of a node.' ),
'group' => t ( 'Comment' ),
'base' => 'comment' ,
'base field' => 'cid' ,
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
'label' => t ( 'Last Comment' ),
),
);
// last_comment_uid
$data [ 'node_comment_statistics' ][ 'last_comment_uid' ] = array (
'title' => t ( 'Last comment uid' ),
'help' => t ( 'The User ID of the author of the last comment of a node.' ),
'relationship' => array (
'title' => t ( 'Last comment author' ),
'base' => 'users' ,
'base field' => 'uid' ,
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
'label' => t ( 'Last comment author' ),
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'numeric' ,
2009-05-17 11:16:51 +00:00
),
'argument' => array (
2012-08-11 11:46:07 +00:00
'id' => 'numeric' ,
2009-05-17 11:16:51 +00:00
),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'numeric' ,
2009-05-17 11:16:51 +00:00
),
);
return $data ;
}
/**
* Use views_data_alter to add items to the node table that are
* relevant to comments .
*/
function comment_views_data_alter ( & $data ) {
// new comments
$data [ 'node' ][ 'new_comments' ] = array (
'title' => t ( 'New comments' ),
'help' => t ( 'The number of new comments on the node.' ),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'node_new_comments' ,
2009-05-17 11:16:51 +00:00
'no group by' => TRUE ,
),
);
$data [ 'node' ][ 'comments_link' ] = array (
'field' => array (
'title' => t ( 'Add comment link' ),
'help' => t ( 'Display the standard add comment link used on regular nodes, which will only display if the viewing user has access to add a comment.' ),
2012-08-11 11:46:07 +00:00
'id' => 'comment_node_link' ,
2009-05-17 11:16:51 +00:00
),
);
// Comment status of the node
$data [ 'node' ][ 'comment' ] = array (
'title' => t ( 'Comment status' ),
'help' => t ( 'Whether comments are enabled or disabled on the node.' ),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'node_comment' ,
2009-05-17 11:16:51 +00:00
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'node_comment' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'node' ][ 'uid_touch' ] = array (
'title' => t ( 'User posted or commented' ),
'help' => t ( 'Display nodes only if a user posted the node or commented on the node.' ),
'argument' => array (
'field' => 'uid' ,
'name table' => 'users' ,
'name field' => 'name' ,
2012-08-11 11:46:07 +00:00
'id' => 'argument_comment_user_uid' ,
2009-05-17 11:16:51 +00:00
'no group by' => TRUE ,
),
'filter' => array (
'field' => 'uid' ,
'name table' => 'users' ,
'name field' => 'name' ,
2012-08-11 11:46:07 +00:00
'id' => 'comment_user_uid' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'node' ][ 'cid' ] = array (
'title' => t ( 'Comments of the node' ),
'help' => t ( 'Relate all comments on the node. This will create 1 duplicate record for every comment. Usually if you need this it is better to create a comment view.' ),
'relationship' => array (
'group' => t ( 'Comment' ),
'label' => t ( 'Comments' ),
'base' => 'comment' ,
'base field' => 'nid' ,
'relationship field' => 'nid' ,
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
);
}