comment_views_data_alter(&$data)
Implements hook_views_data_alter().
File
- core/modules/comment/comment.views.inc, line 11
- Provide views data for comment.module.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | 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, ), ); // Provide a integration for each entity type except comment. foreach (\Drupal::entityManager()->getDefinitions() as $entity_type_id => $entity_type ) { if ( $entity_type_id == 'comment' || ! $entity_type ->isSubclassOf( '\Drupal\Core\Entity\ContentEntityInterface' ) || ! $entity_type ->getBaseTable()) { continue ; } $fields = \Drupal::service( 'comment.manager' )->getFields( $entity_type_id ); $base_table = $entity_type ->getDataTable() ? : $entity_type ->getBaseTable(); $args = array ( '@entity_type' => $entity_type_id ); 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' , ), ); // Multilingual properties are stored in data table. if (!( $table = $entity_type ->getDataTable())) { $table = $entity_type ->getBaseTable(); } $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_field_data' , 'name field' => 'name' , 'id' => 'argument_comment_user_uid' , 'no group by' => TRUE, 'entity_type' => $entity_type_id , 'entity_id' => $entity_type ->getKey( 'id' ), ), 'filter' => array ( 'field' => 'uid' , 'name table' => 'users_field_data' , 'name field' => 'name' , 'id' => 'comment_user_uid' , 'entity_type' => $entity_type_id , 'entity_id' => $entity_type ->getKey( '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_field_data' , 'base field' => 'entity_id' , 'relationship field' => $entity_type ->getKey( 'id' ), 'id' => 'standard' , 'extra' => array ( array ( 'field' => 'entity_type' , 'value' => $entity_type_id , ), array ( 'field' => 'field_name' , 'value' => $field_name , ), ), ), ); } } } } |
Please login to continue.