function dynamic_entity_reference_get_referenceable_entities in Dynamic Entity Reference 7
Gets referenceable entities.
Parameters
string $target_type: The target entity type.
string|null $match: (Optional) Text to match the label against. Defaults to NULL.
string $match_operator: (Optional) The operation the matching should be done with. Defaults to "CONTAINS".
int $limit: The query limit.
Return value
array Array of entity labels keyed by bundle and ID.
1 call to dynamic_entity_reference_get_referenceable_entities()
- dynamic_entity_reference_autocomplete in ./
dynamic_entity_reference.pages.inc - Dynamic entity reference auto-complete callback.
File
- ./
dynamic_entity_reference.pages.inc, line 85 - Contains page callbacks for the module.
Code
function dynamic_entity_reference_get_referenceable_entities($target_type, $match, $match_operator, $limit) {
$query = dynamic_entity_reference_build_entity_query($target_type, $match, $match_operator);
$query
->range(0, $limit);
$result = $query
->execute();
if (empty($result) || empty($result[$target_type])) {
return array();
}
$options = array();
$entities = entity_load($target_type, array_keys($result[$target_type]));
foreach ($entities as $entity_id => $entity) {
/** @var \EntityDrupalWrapper $wrapper */
$wrapper = entity_metadata_wrapper($target_type, $entity);
$bundle = $wrapper
->getBundle();
$options[$bundle][$entity_id] = check_plain($wrapper
->label());
}
return $options;
}