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
*/
2013-09-27 15:34:47 +00:00
/**
* 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.
2014-03-04 13:27:58 +00:00
foreach ( \Drupal :: entityManager () -> getDefinitions () as $entity_type_id => $entity_type ) {
if ( $entity_type_id == 'comment' || ! $entity_type -> isFieldable () || ! $entity_type -> getBaseTable ()) {
2013-09-27 15:34:47 +00:00
continue ;
}
2014-03-04 13:27:58 +00:00
$fields = \Drupal :: service ( 'comment.manager' ) -> getFields ( $entity_type_id );
$base_table = $entity_type -> getBaseTable ();
$args = array ( '@entity_type' => $entity_type_id );
2013-09-27 15:34:47 +00:00
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' ,
),
);
2014-07-11 10:37:14 +00:00
// Multilingual properties are stored in data table.
if ( ! ( $table = $entity_type -> getDataTable ())) {
$table = $entity_type -> getBaseTable ();
2013-09-27 15:34:47 +00:00
}
$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' ,
2014-08-14 05:21:28 +00:00
'name table' => 'users_field_data' ,
2013-09-27 15:34:47 +00:00
'name field' => 'name' ,
'id' => 'argument_comment_user_uid' ,
'no group by' => TRUE ,
2014-03-04 13:27:58 +00:00
'entity_type' => $entity_type_id ,
'entity_id' => $entity_type -> getKey ( 'id' ),
2013-09-27 15:34:47 +00:00
),
'filter' => array (
'field' => 'uid' ,
2014-08-14 05:21:28 +00:00
'name table' => 'users_field_data' ,
2013-09-27 15:34:47 +00:00
'name field' => 'name' ,
'id' => 'comment_user_uid' ,
2014-03-04 13:27:58 +00:00
'entity_type' => $entity_type_id ,
'entity_id' => $entity_type -> getKey ( 'id' ),
2013-09-27 15:34:47 +00:00
),
);
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' ),
2014-07-11 10:37:14 +00:00
'base' => 'comment_field_data' ,
2013-09-27 15:34:47 +00:00
'base field' => 'entity_id' ,
2014-03-04 13:27:58 +00:00
'relationship field' => $entity_type -> getKey ( 'id' ),
2013-09-27 15:34:47 +00:00
'id' => 'standard' ,
'extra' => array (
array (
'field' => 'entity_type' ,
2014-03-04 13:27:58 +00:00
'value' => $entity_type_id ,
2013-09-27 15:34:47 +00:00
),
array (
2014-06-13 09:34:04 +00:00
'field' => 'field_name' ,
'value' => $field_name ,
2013-09-27 15:34:47 +00:00
),
),
),
);
}
}
}
2009-05-17 11:16:51 +00:00
}