1 EntityReferenceSelectionHandlerGeneric.inc | protected EntityReferenceSelectionHandlerGeneric::buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS') |
Build an EntityFieldQuery to get referenceable entities.
File
- core/
modules/ entityreference/ plugins/ selection/ EntityReferenceSelectionHandlerGeneric.inc, line 270 - Generic Entity handler.
Class
- EntityReferenceSelectionHandlerGeneric
- @file Generic Entity handler.
Code
protected function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS') {
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', $this->field['settings']['target_type']);
if (!empty($this->field['settings']['handler_settings']['target_bundles'])) {
$query->entityCondition('bundle', $this->field['settings']['handler_settings']['target_bundles'], 'IN');
}
if (isset($match)) {
if (!empty($this->label_key)) {
$query->propertyCondition($this->label_key, $match, $match_operator);
}
}
// Add a generic entity access tag to the query.
$query->addTag($this->field['settings']['target_type'] . '_access');
$query->addTag('entityreference');
$query->addMetaData('field', $this->field);
$query->addMetaData('entityreference_selection_handler', $this);
// Add the sort option.
if (!empty($this->field['settings']['handler_settings']['sort'])) {
$sort_settings = $this->field['settings']['handler_settings']['sort'];
if ($sort_settings['type'] == 'property') {
$query->propertyOrderBy($sort_settings['property'], $sort_settings['direction']);
}
elseif ($sort_settings['type'] == 'field') {
list($field, $column) = explode(':', $sort_settings['field'], 2);
$query->fieldOrderBy($field, $column, $sort_settings['direction']);
}
}
return $query;
}