public function EntityReference_SelectionHandler_Generic::ensureBaseTable in Entity reference 7
Ensure a base table exists for the query.
If we have a field-only query, we want to assure we have a base-table so we can later alter the query in entityFieldQueryAlter().
Parameters
$query: The Select query.
Return value
The alias of the base-table.
3 calls to EntityReference_SelectionHandler_Generic::ensureBaseTable()
- EntityReference_SelectionHandler_Generic_comment::entityFieldQueryAlter in plugins/
selection/ EntityReference_SelectionHandler_Generic.class.php - Implements EntityReferenceHandler::entityFieldQueryAlter().
- EntityReference_SelectionHandler_Generic_node::entityFieldQueryAlter in plugins/
selection/ EntityReference_SelectionHandler_Generic.class.php - Implements EntityReferenceHandler::entityFieldQueryAlter().
- EntityReference_SelectionHandler_Generic_taxonomy_term::entityFieldQueryAlter in plugins/
selection/ EntityReference_SelectionHandler_Generic.class.php - Implements EntityReferenceHandler::entityFieldQueryAlter().
File
- plugins/
selection/ EntityReference_SelectionHandler_Generic.class.php, line 327
Class
- EntityReference_SelectionHandler_Generic
- A generic Entity handler.
Code
public function ensureBaseTable(SelectQueryInterface $query) {
$tables = $query
->getTables();
// Check the current base table.
foreach ($tables as $table) {
if (empty($table['join'])) {
$alias = $table['alias'];
break;
}
}
if (strpos($alias, 'field_data_') !== 0) {
// The existing base-table is the correct one.
return $alias;
}
// Join the known base-table.
$target_type = $this->field['settings']['target_type'];
$entity_info = entity_get_info($target_type);
$target_type_base_table = $entity_info['base table'];
$id = $entity_info['entity keys']['id'];
// Return the alias of the table.
return $query
->innerJoin($target_type_base_table, NULL, "%alias.{$id} = {$alias}.entity_id");
}