Skip to content

Instantly share code, notes, and snippets.

@xjm
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xjm/151a4b97ad482abe96ad to your computer and use it in GitHub Desktop.
Save xjm/151a4b97ad482abe96ad to your computer and use it in GitHub Desktop.
<?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;
}
@xjm
Copy link
Author

xjm commented May 21, 2014

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. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment