label needs check_plain().
[project/relation.git] / views / relation.views.inc
1 <?php
2
3 /**
4 * Implements hook_views_data_alter().
5 */
6 function relation_views_data_alter(&$data) {
7 // Find out which entity type has which base table.
8 $entity_infos = module_invoke_all('entity_info');
9 $entity_tables = array();
10 foreach ($entity_infos as $entity_type => $entity_info) {
11 if (isset($entity_info['base table'])) {
12 $entity_tables[$entity_type] = $entity_info['base table'];
13 }
14 }
15
16 // Build the relations between the different tables.
17 $types = relation_get_types();
18 foreach ($types as $predicate => $relation_type) {
19 if ($relation_type->max_arity != 2) {
20 continue;
21 }
22 $target_index = $relation_type->directional ? 'target_bundles' : 'source_bundles';
23 foreach ($relation_type->source_bundles as $source_bundle) {
24 $source_bundle = explode(':', $source_bundle, 2);
25 $entity_type_left = $source_bundle[0];
26 foreach ($relation_type->$target_index as $target_bundle) {
27 $target_bundle = explode(':', $target_bundle, 2);
28 $entity_type_right = $target_bundle[0];
29 $base_table_left = $entity_tables[$entity_type_left];
30 $base_table_right = $entity_tables[$entity_type_right];
31
32 $t_arguments = array(
33 '@left' => $entity_type_left,
34 '@right' => $entity_type_right,
35 '@predicate_label' => $relation_type->label,
36 );
37 $data[$base_table_left]['relation_' . $predicate . '_' . $entity_type_right] = array(
38 'title' => t('Relation: @predicate_label (@left <-> @right)', $t_arguments),
39 'help' => t('Provides a relationship from @left to @right via the relation @predicate_label', $t_arguments),
40 'relationship' => array(
41 'label' => check_plain($relation_type->label),
42 'base' => $base_table_right,
43 'base field' => $entity_infos[$entity_type_right]['entity keys']['id'],
44 'relationship field' => $entity_infos[$entity_type_left]['entity keys']['id'],
45 'handler' => 'relation_handler_relationship',
46 'predicate' => $predicate,
47 'entity_type_left' => $entity_type_left,
48 'entity_type_right' => $entity_type_right,
49 'join_handler' => 'relation_handler_join',
50 ),
51 );
52 }
53 }
54 }
55 }