function tripal_views_views_data_alter
2.x tripal_views.views.inc | tripal_views_views_data_alter(&$data) |
1.x tripal_views.views.inc | tripal_views_views_data_alter(&$data) |
Implements hook_views_data_alter(). Used to add Chado <-> Node Joins & Relationships since you need to add to the $data['node'] to do this
Related topics
File
- tripal_views/
tripal_views.views.inc, line 532 - Tripal Views Integration
Code
function tripal_views_views_data_alter(&$data) {
// ADD IN NODE JOINS & RELATIONSHIPS
// D7 @todo: Create custom handler to allow join from Node => Base (ie: organism)
// with the addition of a single relationship
// D7 @todo: Create custom handler to allow join from Base (ie: organism)
// with the addition of a single relationship
// D7 @todo: Add support for Mview <-> Node joins and relationships
$tvi_query = db_query('SELECT * FROM {tripal_views} WHERE base_table=1');
foreach ($tvi_query as $tvi_row) {
//ids we'll use for queries
$setup_id = $tvi_row->setup_id;
$base_table = $tvi_row->table_name;
$linker_table = 'chado_' . $base_table;
$base_title = ucwords(str_replace('_', ' ', $base_table));
// add in joins to the node tables if the Chado schema is local
if (chado_is_local()) {
// if a node linking table exists then add in the joins
if (db_table_exists($linker_table)) {
// Adds content (node) fields to chado base table field lists automatically
$data['node']['table']['join'][$linker_table] = array(
'left_field' => 'nid',
'field' => 'nid',
);
$data[$linker_table]['table']['join'][$base_table] = array(
'left_field' => $base_table . '_id',
'field' => $base_table . '_id',
);
$data['node']['table']['join'][$base_table] = array(
'left_table' => $linker_table,
'left_field' => 'nid',
'field' => 'nid',
);
// Adds in a chado base table => node relationship
// This allows controlled joining to multiple nodes per line
// Use Case: link to feature and organism nodes on a feature listing
// D7 todo: a custom relationship handler to get from feature.organism_id => organism node
// without 1st needing to add relationship to organism table
$base_field = $base_table . '_id';
$data[$linker_table][$base_field] = array(
'group' => $base_title,
'title' => $base_title . 'Node',
'help' => t("Links @base_title to it's node.", array('@base_title' => $base_title)),
'relationship' => array(
'handler' => 'views_handler_relationship',
'title' => t("@base_title => Node", array('@base_title' => $base_title)),
'label' => t("@base_title => Node", array('@base_title' => $base_title)),
'real field' => 'nid',
'base' => 'node',
'base field' => 'nid'
),
);
// Add Chado fields to a node-based view
// This will only be done with relationships
$base_field = $base_table . '_id';
$data['node'][$base_field] = array(
'group' => $base_title,
'title' => $base_title,
'help' => t("Links node to chado @base_title.", array('@base_title' => $base_title)),
'relationship' => array(
'handler' => 'views_handler_relationship',
'title' => t("Node => @base_title", array('@base_title' => $base_title)),
'label' => t("Node => @base_title", array('@base_title' => $base_title)),
'real field' => 'nid',
'base' => $linker_table,
'base field' => 'nid'
),
);
}
}
}
return $data;
}