public function entity_views_handler_relationship_by_bundle::query in Entity API 7
Called to implement a relationship in a query.
Mostly the same as the parent method, except we add an extra clause to the join.
Overrides views_handler_relationship::query
File
- views/
handlers/ entity_views_handler_relationship_by_bundle.inc, line 79 - Contains the entity_views_handler_relationship_by_bundle class.
Class
- entity_views_handler_relationship_by_bundle
- Relationship handler for entity relationships that may limit the join to one or more bundles.
Code
public function query() {
$table_data = views_fetch_data($this->definition['base']);
$base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field'];
$this
->ensure_my_table();
$def = $this->definition;
$def['table'] = $this->definition['base'];
$def['field'] = $base_field;
$def['left_table'] = $this->table_alias;
$def['left_field'] = $this->field;
if (!empty($this->options['required'])) {
$def['type'] = 'INNER';
}
// Add an extra clause to the join if there are bundle types selected.
if ($this->options['bundle_types']) {
$entity_info = entity_get_info($table_data['table']['entity type']);
$def['extra'] = array(
array(
// The table and the IN operator are implicit.
'field' => $entity_info['entity keys']['bundle'],
'value' => $this->options['bundle_types'],
),
);
}
if (!empty($def['join_handler']) && class_exists($def['join_handler'])) {
$join = new $def['join_handler']();
}
else {
$join = new views_join();
}
$join->definition = $def;
$join
->construct();
$join->adjusted = TRUE;
// Use a short alias for this.
$alias = $def['table'] . '_' . $this->table;
$this->alias = $this->query
->add_relationship($alias, $join, $this->definition['base'], $this->relationship);
}