protected function FieldInstanceEntityController::buildQuery in Field entity 7
Builds the query to load the entity.
This has full revision support. For entities requiring special queries, the class can be extended, and the default query can be constructed by calling parent::buildQuery(). This is usually necessary when the object being loaded needs to be augmented with additional data from another table, such as loading node type into comments or vocabulary machine name into terms, however it can also support $conditions on different tables. See CommentController::buildQuery() or TaxonomyTermController::buildQuery() for examples.
Parameters
$ids: An array of entity IDs, or FALSE to load all entities.
$conditions: An array of conditions. Keys are field names on the entity's base table. Values will be compared for equality. All the comparisons will be ANDed together. This parameter is deprecated; use an EntityFieldQuery instead.
$revision_id: The ID of the revision to load, or FALSE if this query is asking for the most current revision(s).
Return value
SelectQuery A SelectQuery object for loading the entity.
Overrides DrupalDefaultEntityController::buildQuery
File
- ./
field_entity.module, line 111 - Field and Field Instance entity definitions.
Class
- FieldInstanceEntityController
- Class FieldInstanceEntityController.
Code
protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
$bundle_values = array();
if ($conditions) {
foreach ($conditions as $field => $value) {
if ($field === 'entity_type_bundle') {
$bundle_values[] = $value;
}
}
unset($conditions['entity_type_bundle']);
}
$query = parent::buildQuery($ids, $conditions, $revision_id);
foreach ($bundle_values as $value) {
list($entity_type, $bundle) = explode(':', $value, 2);
$query
->condition('base.entity_type', $entity_type, '=');
$query
->condition('base.bundle', $bundle, '=');
}
$query
->addExpression("CONCAT(CONCAT(base.entity_type, ':'), base.bundle)", 'entity_type_bundle');
return $query;
}