2009-05-17 11:16:51 +00:00
< ? php
/**
* @ file
2013-11-20 18:38:33 +00:00
* Provide views data for comment . module .
2009-05-17 11:16:51 +00:00
*/
/**
* Implements hook_views_data () .
*/
function comment_views_data () {
2013-02-27 22:57:18 +00:00
// Define the base group of this table. Fields that don't have a group defined
// will go into this field by default.
2009-05-17 11:16:51 +00:00
$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
$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
),
);
$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
),
);
$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
),
);
$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
),
);
$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' ,
2013-09-27 15:34:47 +00:00
),
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
),
);
$data [ 'comment' ][ 'mail' ] = array (
2013-02-09 22:07:15 +00:00
'title' => t ( 'E-mail' ),
'help' => t ( 'E-mail of user that posted the comment. Will be empty if the author is a registered user.' ),
2009-05-17 11:16:51 +00:00
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2013-09-27 15:34:47 +00:00
),
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
),
);
$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
),
);
2013-10-13 12:21:03 +00:00
if ( \Drupal :: moduleHandler () -> moduleExists ( 'language' )) {
2012-08-26 19:44:59 +00:00
$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
$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' ,
2013-03-27 04:52:36 +00:00
'id' => 'date_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' ,
2013-03-27 04:52:36 +00:00
'id' => 'date_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' ,
2013-03-27 04:52:36 +00:00
'id' => 'date_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' ,
2013-03-27 04:52:36 +00:00
'id' => 'date_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' ,
2013-03-27 04:52:36 +00:00
'id' => 'date_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' ,
2013-03-27 04:52:36 +00:00
'id' => 'date_week' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'comment' ][ 'status' ] = array (
2013-02-09 22:07:15 +00:00
'title' => t ( 'Approved status' ),
2009-05-17 11:16:51 +00:00
'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' ,
2013-02-09 22:07:15 +00:00
'label' => t ( 'Approved comment status' ),
2009-05-17 11:16:51 +00:00
'type' => 'yes-no' ,
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'comment' ][ 'view_comment' ] = array (
'field' => array (
2013-02-09 22:07:15 +00:00
'title' => t ( 'Link to comment' ),
2009-05-17 11:16:51 +00:00
'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
),
);
$data [ 'comment' ][ 'edit_comment' ] = array (
'field' => array (
2013-02-09 22:07:15 +00:00
'title' => t ( 'Link to edit comment' ),
2009-05-17 11:16:51 +00:00
'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
),
);
$data [ 'comment' ][ 'delete_comment' ] = array (
'field' => array (
2013-02-09 22:07:15 +00:00
'title' => t ( 'Link to delete comment' ),
2009-05-17 11:16:51 +00:00
'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
),
);
$data [ 'comment' ][ 'approve_comment' ] = array (
'field' => array (
2013-02-09 22:07:15 +00:00
'title' => t ( 'Link to approve comment' ),
2009-05-17 11:16:51 +00:00
'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
),
);
$data [ 'comment' ][ 'replyto_comment' ] = array (
'field' => array (
2013-02-09 22:07:15 +00:00
'title' => t ( 'Link to reply-to comment' ),
2009-05-17 11:16:51 +00:00
'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
),
);
2013-09-27 15:34:47 +00:00
$data [ 'comment' ][ 'entity_id' ] = array (
'title' => t ( 'Entity ID' ),
'help' => t ( 'The Entity ID to which the comment is a reply to.' ),
'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' => '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
),
2013-09-27 15:34:47 +00:00
'sort' => array (
'id' => 'standard' ,
),
);
$data [ 'comment' ][ 'entity_type' ] = array (
'title' => t ( 'Entity type' ),
'help' => t ( 'The Entity type to which the comment is a reply to.' ),
2009-05-17 11:16:51 +00:00
'field' => array (
2013-09-27 15:34:47 +00:00
'id' => 'standard' ,
),
'filter' => array (
'id' => 'string' ,
),
'argument' => array (
'id' => 'string' ,
),
'sort' => array (
'id' => 'standard' ,
),
);
$data [ 'comment' ][ 'field_id' ] = array (
'title' => t ( 'Comment field id' ),
'help' => t ( 'The Field id from which the comment originated.' ),
'field' => array (
'id' => 'standard' ,
),
'filter' => array (
'id' => 'string' ,
),
'argument' => array (
'id' => 'string' ,
),
'sort' => array (
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
);
2013-09-27 15:34:47 +00:00
$entities_info = \Drupal :: entityManager () -> getDefinitions ();
// Provide a relationship for each entity type except comment.
foreach ( $entities_info as $type => $entity_info ) {
if ( $type == 'comment' || empty ( $entity_info [ 'fieldable' ]) || ! isset ( $entity_info [ 'base_table' ])) {
continue ;
}
if ( $fields = \Drupal :: service ( 'comment.manager' ) -> getFields ( $type )) {
$data [ 'comment' ][ $type ] = array (
'relationship' => array (
'title' => $entity_info [ 'label' ],
'help' => t ( 'The @entity_type to which the comment is a reply to.' , array ( '@entity_type' => $entity_info [ 'label' ])),
'base' => $entity_info [ 'base_table' ],
'base field' => $entity_info [ 'entity_keys' ][ 'id' ],
'relationship field' => 'entity_id' ,
'id' => 'standard' ,
'label' => $entity_info [ 'label' ],
'extra' => array (
array (
'field' => 'entity_type' ,
'value' => $type ,
'table' => 'comment'
),
),
),
);
}
}
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-09-16 03:58:06 +00:00
if ( \Drupal :: moduleHandler () -> moduleExists ( 'content_translation' )) {
2013-01-25 20:32:06 +00:00
$data [ 'comment' ][ 'translation_link' ] = array (
'title' => t ( 'Translation link' ),
'help' => t ( 'Provide a link to the translations overview for comments.' ),
'field' => array (
2013-06-25 19:16:20 +00:00
'id' => 'content_translation_link' ,
2013-01-25 20:32:06 +00:00
),
);
}
2013-02-27 22:57:18 +00:00
// Define the base group of this table. Fields that don't have a group defined
// will go into this field by default.
2013-09-27 15:34:47 +00:00
$data [ 'comment_entity_statistics' ][ 'table' ][ 'group' ] = t ( 'Comment Statistics' );
// Provide a relationship for each entity type except comment.
foreach ( $entities_info as $type => $entity_info ) {
if ( $type == 'comment' || empty ( $entity_info [ 'fieldable' ]) || ! isset ( $entity_info [ 'base_table' ])) {
continue ;
}
// This relationship does not use the 'field id' column, if the entity has
// multiple comment-fields, then this might introduce duplicates, in which
// case the site-builder should enable aggregation and SUM the comment_count
// field. We cannot create a relationship from the base table to
// {comment_entity_statistics} for each field as multiple joins between
// the same two tables is not supported.
if ( \Drupal :: service ( 'comment.manager' ) -> getFields ( $type )) {
$data [ 'comment_entity_statistics' ][ 'table' ][ 'join' ][ $entity_info [ 'base_table' ]] = array (
'type' => 'INNER' ,
'left_field' => $entity_info [ 'entity_keys' ][ 'id' ],
'field' => 'entity_id' ,
'extra' => array (
array (
'field' => 'entity_type' ,
'value' => $type ,
),
),
);
}
}
2009-05-17 11:16:51 +00:00
2013-09-27 15:34:47 +00:00
$data [ 'comment_entity_statistics' ][ 'last_comment_timestamp' ] = array (
2009-05-17 11:16:51 +00:00
'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
),
);
2013-09-27 15:34:47 +00:00
$data [ 'comment_entity_statistics' ][ 'last_comment_name' ] = array (
2009-05-17 11:16:51 +00:00
'title' => t ( " Last comment author " ),
'help' => t ( 'The name of the author of the last posted comment.' ),
'field' => array (
2013-09-27 15:34:47 +00:00
'id' => 'comment_ces_last_comment_name' ,
2009-05-17 11:16:51 +00:00
'no group by' => TRUE ,
),
'sort' => array (
2013-09-27 15:34:47 +00:00
'id' => 'comment_ces_last_comment_name' ,
2009-05-17 11:16:51 +00:00
'no group by' => TRUE ,
),
);
2013-09-27 15:34:47 +00:00
$data [ 'comment_entity_statistics' ][ 'comment_count' ] = array (
2009-05-17 11:16:51 +00:00
'title' => t ( 'Comment count' ),
2013-09-27 15:34:47 +00:00
'help' => t ( 'The number of comments an entity has.' ),
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
),
'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
),
);
2013-09-27 15:34:47 +00:00
$data [ 'comment_entity_statistics' ][ 'last_updated' ] = array (
2009-05-17 11:16:51 +00:00
'title' => t ( 'Updated/commented date' ),
2013-09-27 15:34:47 +00:00
'help' => t ( 'The most recent of last comment posted or entity updated time.' ),
2009-05-17 11:16:51 +00:00
'field' => array (
2013-09-27 15:34:47 +00:00
'id' => 'comment_ces_last_updated' ,
2009-05-17 11:16:51 +00:00
'no group by' => TRUE ,
),
'sort' => array (
2013-09-27 15:34:47 +00:00
'id' => 'comment_ces_last_updated' ,
2009-05-17 11:16:51 +00:00
'no group by' => TRUE ,
),
'filter' => array (
2013-09-27 15:34:47 +00:00
'id' => 'comment_ces_last_updated' ,
2009-05-17 11:16:51 +00:00
),
);
2013-09-27 15:34:47 +00:00
$data [ 'comment_entity_statistics' ][ 'cid' ] = array (
2009-05-17 11:16:51 +00:00
'title' => t ( 'Last comment CID' ),
2013-09-27 15:34:47 +00:00
'help' => t ( 'Display the last comment of an entity' ),
2009-05-17 11:16:51 +00:00
'relationship' => array (
2013-02-09 22:07:15 +00:00
'title' => t ( 'Last comment' ),
2013-09-27 15:34:47 +00:00
'help' => t ( 'The last comment of an entity.' ),
2009-05-17 11:16:51 +00:00
'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' ),
),
);
2013-09-27 15:34:47 +00:00
$data [ 'comment_entity_statistics' ][ 'last_comment_uid' ] = array (
2009-05-17 11:16:51 +00:00
'title' => t ( 'Last comment uid' ),
2013-09-27 15:34:47 +00:00
'help' => t ( 'The User ID of the author of the last comment of an entity.' ),
2009-05-17 11:16:51 +00:00
'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
),
);
2013-09-27 15:34:47 +00:00
$data [ 'comment_entity_statistics' ][ 'entity_type' ] = array (
'title' => t ( 'Entity type' ),
'help' => t ( 'The entity type to which the comment is a reply to.' ),
2009-05-17 11:16:51 +00:00
'field' => array (
2013-09-27 15:34:47 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
2013-09-27 15:34:47 +00:00
'filter' => array (
'id' => 'string' ,
2009-05-17 11:16:51 +00:00
),
2013-09-27 15:34:47 +00:00
'argument' => array (
'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
),
2013-09-27 15:34:47 +00:00
);
$data [ 'comment_entity_statistics' ][ 'field_id' ] = array (
'title' => t ( 'Comment field ID' ),
'help' => t ( 'The field ID from which the comment originated.' ),
'field' => array (
'id' => 'standard' ,
),
2009-05-17 11:16:51 +00:00
'filter' => array (
2013-09-27 15:34:47 +00:00
'id' => 'string' ,
2009-05-17 11:16:51 +00:00
),
'argument' => array (
2013-09-27 15:34:47 +00:00
'id' => 'string' ,
2009-05-17 11:16:51 +00:00
),
2013-09-27 15:34:47 +00:00
'sort' => array (
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
);
2013-09-27 15:34:47 +00:00
return $data ;
}
/**
* Implements hook_views_data_alter () .
*/
function comment_views_data_alter ( & $data ) {
// New comments are only supported for node table because it requires the
// history table.
$data [ 'node' ][ 'new_comments' ] = array (
'title' => t ( 'New comments' ),
'help' => t ( 'The number of new comments on the node.' ),
'field' => array (
'id' => 'node_new_comments' ,
'no group by' => TRUE ,
2009-05-17 11:16:51 +00:00
),
);
2013-09-27 15:34:47 +00:00
// Provide a integration for each entity type except comment.
foreach ( \Drupal :: entityManager () -> getDefinitions () as $entity_type => $entity_info ) {
if ( $entity_type == 'comment' || empty ( $entity_info [ 'fieldable' ]) || ! isset ( $entity_info [ 'base_table' ])) {
continue ;
}
$fields = \Drupal :: service ( 'comment.manager' ) -> getFields ( $entity_type );
$base_table = $entity_info [ 'base_table' ];
$args = array ( '@entity_type' => $entity_type );
if ( $fields ) {
$data [ $base_table ][ 'comments_link' ] = array (
'field' => array (
'title' => t ( 'Add comment link' ),
'help' => t ( 'Display the standard add comment link used on regular @entity_type, which will only display if the viewing user has access to add a comment.' , $args ),
'id' => 'comment_entity_link' ,
),
);
if ( $entity_info [ 'id' ] == 'node' ) {
// Node properties lives in data_table.
$table = $entity_info [ 'data_table' ];
}
else {
$table = $base_table ;
}
$data [ $table ][ 'uid_touch' ] = array (
'title' => t ( 'User posted or commented' ),
'help' => t ( 'Display nodes only if a user posted the @entity_type or commented on the @entity_type.' , $args ),
'argument' => array (
'field' => 'uid' ,
'name table' => 'users' ,
'name field' => 'name' ,
'id' => 'argument_comment_user_uid' ,
'no group by' => TRUE ,
'entity_type' => $entity_type ,
'entity_id' => $entity_info [ 'entity_keys' ][ 'id' ],
),
'filter' => array (
'field' => 'uid' ,
'name table' => 'users' ,
'name field' => 'name' ,
'id' => 'comment_user_uid' ,
'entity_type' => $entity_type ,
'entity_id' => $entity_info [ 'entity_keys' ][ 'id' ],
),
);
foreach ( $fields as $field_name => $field ) {
$data [ $base_table ][ $field_name . '_cid' ] = array (
'title' => t ( 'Comments of the @entity_type using field: @field_name' , $args + array ( '@field_name' => $field_name )),
'help' => t ( 'Relate all comments on the @entity_type. This will create 1 duplicate record for every comment. Usually if you need this it is better to create a comment view.' , $args ),
'relationship' => array (
'group' => t ( 'Comment' ),
'label' => t ( 'Comments' ),
'base' => 'comment' ,
'base field' => 'entity_id' ,
'relationship field' => $entity_info [ 'entity_keys' ][ 'id' ],
'id' => 'standard' ,
'extra' => array (
array (
'field' => 'entity_type' ,
'value' => $entity_type ,
),
array (
'field' => 'field_id' ,
'value' => $entity_type . '.' . $field_name ,
),
),
),
);
}
}
}
2009-05-17 11:16:51 +00:00
}
2013-06-09 12:35:39 +00:00
/**
* Implements hook_views_plugins_row_alter () .
*
* Replaces the generic row plugin by a custom one for comments .
*
* @ see \Drupal\views\Plugin\views\row\EntityRow
*/
function comment_views_plugins_row_alter ( array & $plugins ) {
$plugins [ 'entity:comment' ][ 'class' ] = 'Drupal\comment\Plugin\views\row\CommentRow' ;
2013-09-11 01:21:44 +00:00
$plugins [ 'entity:comment' ][ 'provider' ] = 'comment' ;
2013-06-09 12:35:39 +00:00
}