public function entityFieldQueryAlter(SelectQueryInterface $query) { // The Taxonomy module doesn't implement any proper taxonomy term access, // and as a consequence doesn't make sure that taxonomy terms cannot be viewed // when the user doesn't have access to the vocabulary. $tables = $query->getTables(); $base_table = key($tables); $vocabulary_alias = $query->innerJoin('taxonomy_vocabulary', 'n', '%alias.vid = ' . $base_table . '.vid'); $query->addMetadata('base_table', $vocabulary_alias); // Pass the query to the taxonomy access control. $this->reAlterQuery($query, 'taxonomy_vocabulary_access', $vocabulary_alias); // Also, the taxonomy term entity exposes a bundle, but doesn't have a bundle // column in the database. We have to alter the query ourself to go fetch // the bundle. $conditions =& $query->conditions(); foreach ($conditions as $key => &$condition) { if ($key !== '#conjunction' && is_string($condition['field']) && $condition['field'] === 'vocabulary_machine_name') { $condition['field'] = $vocabulary_alias . '.machine_name'; break; } } }
/** * 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(). * * @param $query * The Select query. * * @return * The alias of the base-table. */ 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); $id = $entity_info['entity keys']['id']; // Return the alias of the table. return $query->innerJoin($target_type, NULL, "%alias.{$id} = {$alias}.entity_id"); }
public function innerJoin($table, $alias = NULL, $condition = NULL, $arguments = array()) { return $this->query->innerJoin($table, $alias, $condition, $arguments); }