Interaction with Drupal views hook_views_data

I have a problem with module integration. I need to provide information about the user who added the video and timestamp. The video field is the CCK embedded media field and is stored in the table content_field_3d_party_video.

My table schema:

function MODULE_schema() { $schema = array(); $schema['video_data'] = array( 'description' => t('Users and timestamps for video field'), 'fields' => array( 'value' => array( 'description' => t('Emfield value'), 'type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => '', ), 'uid' => array( 'description' => t('User id'), 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, ), 'timestamp' => array( 'description' => t('Timestamp'), 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, ), ), 'primary key' => array('value'), 'indexes' => array( 'timestamp' => array('timestamp'), 'uid' => array('uid'), ), ); return $schema; } 

Views hook_views_data:

 function MODULE_views_data() { $data = array(); $data['video_data']['table']['group'] = t('Video Data'); $data['video_data']['table']['join'] = array( 'node' => array( 'left_table' => 'content_field_3d_party_video', 'left_field' => 'field_3d_party_video_value', 'field' => 'value', ), 'users' => array( 'left_field' => 'uid', 'field' => 'uid', ), ); $data['video_data']['value'] = array( 'title' => t('Video value'), 'relationship' => array( 'base' => 'content_field_3d_party_video', 'base field' => 'field_3d_party_video_value', 'field' => 'value', 'handler' => 'views_handler_relationship', 'label' => t('Video value'), ), ); $data['video_data']['uid'] = array( 'title' => t('User id'), 'relationship' => array( 'base' => 'users', 'base field' => 'uid', 'field' => 'uid', 'handler' => 'views_handler_relationship', 'label' => t('User id'), ), ); $data['video_data']['timestamp'] = array( 'title' => t('Timestamp field'), 'field' => array( 'handler' => 'views_handler_field_date', 'click sortable' => TRUE, ), 'sort' => array( 'handler' => 'views_handler_sort_date', ), 'filter' => array( 'handler' => 'views_handler_filter_date', ), ); return $data; } 

But my table is not included in the join, and the views generate this SQL:

 SELECT node.nid AS nid, node.title AS node_title, node.language AS node_language, node_data_field_3d_party_video.field_3d_party_video_embed AS node_data_field_3d_party_video_field_3d_party_video_embed, node_data_field_3d_party_video.field_3d_party_video_value AS node_data_field_3d_party_video_field_3d_party_video_value, ... node.type AS node_type, node.vid AS node_vid FROM node node LEFT JOIN content_field_3d_party_video content_field_3d_party_video_video_data ON value = content_field_3d_party_video_video_data.field_3d_party_video_value LEFT JOIN users users_video_data ON uid = users_video_data.uid LEFT JOIN content_field_3d_party_video node_data_field_3d_party_video ON node.vid = node_data_field_3d_party_video.vid WHERE ... 

Take a look at ON **uid** = users_video_data.uid and ON **value** = content_field_3d_party_video_video_data.field_3d_party_video_value

Any help?


The solution found. To correctly join the node table through the cck field, we must specify node_data_field_3d_party_video as left_table instead of content_field_3d_party_video :

 $data['video_data']['table']['join'] = array( 'node' => array( 'left_table' => 'node_data_field_3d_party_video', 'left_field' => 'field_3d_party_video_value', 'field' => 'value', ), 'users' => array( 'left table' => 'users', 'left_field' => 'uid', 'field' => 'uid', ), ); 
+6
source share
1 answer

I posted a survey solution:

To correctly join the node table through the cck field, we must specify node_data_field_3d_party_video as left_table instead of content_field_3d_party_video :

 $data['video_data']['table']['join'] = array( 'node' => array( 'left_table' => 'node_data_field_3d_party_video', 'left_field' => 'field_3d_party_video_value', 'field' => 'value', ), 'users' => array( 'left table' => 'users', 'left_field' => 'uid', 'field' => 'uid', ), ); 
0
source

Source: https://habr.com/ru/post/906844/


All Articles