function eck__bundle__field_autocomplete in Entity Construction Kit (ECK) 7.3
Same name and namespace in other branches
- 7 eck.bundle.inc \eck__bundle__field_autocomplete()
- 7.2 eck.bundle.inc \eck__bundle__field_autocomplete()
Autocomplete functionality for entities using field labels.
File
- ./
eck.bundle.inc, line 445
Code
function eck__bundle__field_autocomplete($entity_type, $bundle, $string = "") {
$field_label = get_bundle_field_label_info($entity_type, $bundle);
$matches = array();
if ($field_label) {
$field = $field_label['field'];
$language = $field_label['language'];
$delta = $field_label['delta'];
$column = $field_label['column'];
$query = new EntityFieldQuery();
// @todo Remove the addmetadata() call below once
// http://drupal.org/node/997394 is fixed.
$query
->addMetadata('account', user_load(1));
$query
->entityCondition('entity_type', $entity_type->name, '=')
->entityCondition('bundle', $bundle->name, '=')
->fieldCondition($field, $column, $string, 'CONTAINS');
$results = $query
->execute();
$entities = entity_load($entity_type->name, array_keys($results[$entity_type->name]));
foreach ($entities as $id => $entity) {
$matches[$id] = $entity->{$field}[$language][$delta][$column];
}
}
drupal_json_output($matches);
}