5 * Definition of views_handler_relationship_entity_reverse.
9 * A relationship handlers which reverse entity references.
11 * @ingroup views_relationship_handlers
13 class views_handler_relationship_entity_reverse extends views_handler_relationship {
14 function init(&$view, &$options) {
15 parent::init($view, $options);
17 $this->field_info = field_info_field($this->definition['field_name']);
21 * Called to implement a relationship in a query.
24 $this->ensure_my_table();
25 // First, relate our base table to the current base table to the
26 // field, using the base table's id field to the field's column.
27 $views_data = views_fetch_data($this->table);
28 $left_field = $views_data['table']['base']['field'];
31 'left_table' => $this->table_alias,
32 'left_field' => $left_field,
33 'table' => $this->definition['field table'],
34 'field' => $this->definition['field field'],
36 if (!empty($this->options['required'])) {
37 $first['type'] = 'INNER';
40 if (!empty($this->definition['join_extra'])) {
41 $first['extra'] = $this->definition['join_extra'];
44 if (!empty($this->definition['join_handler']) && class_exists($this->definition['join_handler'])) {
45 $first_join = new $this->definition['join_handler'];
48 $first_join = new views_join();
50 $first_join->definition = $first;
51 $first_join->construct();
52 $first_join->adjusted = TRUE;
54 $this->first_alias = $this->query->add_table($this->definition['field table'], $this->relationship, $first_join);
56 // Second, relate the field table to the entity specified using
57 // the entity id on the field table and the entity's id field.
59 'left_table' => $this->first_alias,
60 'left_field' => 'entity_id',
61 'table' => $this->definition['base'],
62 'field' => $this->definition['base field'],
65 if (!empty($this->options['required'])) {
66 $second['type'] = 'INNER';
69 if (!empty($this->definition['join_handler']) && class_exists($this->definition['join_handler'])) {
70 $second_join = new $this->definition['join_handler'];
73 $second_join = new views_join();
75 $second_join->definition = $second;
76 $second_join->construct();
77 $second_join->adjusted = TRUE;
79 // use a short alias for this:
80 $alias = $this->definition['field_name'] . '_' . $this->table;
82 $this->alias = $this->query->add_relationship($alias, $second_join, $this->definition['base'], $this->relationship);