EntityReference_SelectionHandler_Merci.class.php in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.3
File
merci_entityref_behavior/plugins/selection/EntityReference_SelectionHandler_Merci.class.php
View source
<?php
class EntityReference_SelectionHandler_Merci extends EntityReference_SelectionHandler_Generic {
public static function getInstance($field, $instance = NULL, $entity_type = NULL, $entity = NULL) {
return new EntityReference_SelectionHandler_Merci($field, $instance, $entity_type, $entity);
}
public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
$options = parent::getReferencableEntities($match, $match_operator, $limit);
$options = array();
$entity_type = $this->field['settings']['target_type'];
$field_item_name = $this->field['field_name'];
$query = $this
->buildEntityFieldQuery($match, $match_operator);
if ($limit > 0) {
$query
->range(0, $limit);
}
$results = $query
->execute();
$items = array();
foreach ($results[$entity_type] as $id => $target) {
$items[] = array(
'target_id' => $id,
);
}
extract(get_object_vars($this));
$langcode = $entity->language;
$errors = array();
foreach ($items as $delta => $target) {
if (isset($errors[$field_item_name][$langcode][$delta])) {
unset($results[$entity_type][$target['target_id']]);
}
}
if (!empty($results[$entity_type])) {
$entities = entity_load($entity_type, array_keys($results[$entity_type]));
foreach ($entities as $entity_id => $entity) {
list(, , $bundle) = entity_extract_ids($entity_type, $entity);
$options[$bundle][$entity_id] = check_plain($this
->getLabel($entity));
}
}
return $options;
}
}