function votingapi_views_data_alter in Voting API 7.3
Same name and namespace in other branches
- 8.3 votingapi.views.inc \votingapi_views_data_alter()
- 6.2 views/votingapi.views.inc \votingapi_views_data_alter()
- 7.2 views/votingapi.views.inc \votingapi_views_data_alter()
Related topics
File
- views/
votingapi.views.inc, line 272 - Provide views data for votingapi.module.
Code
function votingapi_views_data_alter(&$views_data) {
// Add relationship handlers for both tables, for any base tables currently
// available to Views.
//Get all entity types in the system and register as relationship.
$entity_types = entity_get_info();
foreach ($entity_types as $key => $entity_type) {
$default_relationships[] = array(
'description' => $entity_type['label'],
'entity_type' => $key,
'base_table' => $entity_type['base table'],
'entity_id_column' => $entity_type['entity keys']['id'],
'pseudo_vote' => 'votingapi_vote',
// for legacy compatability w/RC1.
'pseudo_cache' => 'votingapi_cache',
);
}
foreach ($default_relationships as $data) {
$pseudo = str_replace(array(
' ',
'-',
'.',
), '_', $data['entity_type'] . '_' . $data['entity_id_column']);
$pseudo_vote = empty($data['pseudo_vote']) ? 'vapi_' . $pseudo : $data['pseudo_vote'];
$pseudo_cache = empty($data['pseudo_cache']) ? 'vapic_' . $pseudo : $data['pseudo_cache'];
$views_data[$data['base_table']][$pseudo_vote]['relationship'] = array(
'title' => 'Votes',
'help' => 'Votes cast by users on ' . $data['description'] . '.',
'base' => 'votingapi_vote',
'field' => 'entity_id',
'relationship field' => $data['entity_id_column'],
'handler' => 'votingapi_views_handler_relationship',
'extra' => array(
array(
'field' => 'entity_type',
'value' => $data['entity_type'],
'numeric' => FALSE,
),
),
);
$views_data[$data['base_table']][$pseudo_cache]['relationship'] = array(
'title' => 'Vote results',
'help' => 'Aggregate results of votes cast on ' . $data['description'] . '.',
'base' => 'votingapi_cache',
'field' => 'entity_id',
'relationship field' => $data['entity_id_column'],
'handler' => 'votingapi_views_handler_relationship',
'extra' => array(
array(
'field' => 'entity_type',
'value' => $data['entity_type'],
'numeric' => FALSE,
),
),
);
}
}