Last active
August 29, 2015 14:01
-
-
Save xjm/151a4b97ad482abe96ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* flag/flag.views.inc | |
* / | |
/** | |
* Implements hook_views_data(). | |
* / | |
function flag_views_data() { | |
$data = array(); | |
// Add the {flagging} table data to a 'Flag' group in the Views UI. | |
$data['flagging']['table']['group'] = t('Flag'); | |
// Define how the {flagging} table should join with {node}. | |
// Note: this is ignoring {flagging}.entity_type and should not. | |
$data['flagging']['table']['join'] = array( | |
'node' => array( | |
'type' => 'INNER', | |
'left_field' => 'nid', | |
'field' => 'entity_id', | |
), | |
); | |
// Expose the {flagging}.entity_id field. | |
$data['flagging']['entity_id'] = array( | |
'title' => t('Entity ID'), | |
'help' => t('The ID of the entity'), | |
// Add a sort criterion based on the entity_id field. | |
'sort' => array( | |
'id' => 'standard', | |
), | |
); | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that this is not at all sufficient to integrate Flag with node views since it's ignoring the {flagging}.entity_type field, plus a sort criterion for nodes based on {flagging}.entity_id is silly anyway. It just demonstrates that the hook_views_data() is being parsed by Views and generating a valid SQL query with the table and field. :)