You are here

class EntityReference_SelectionHandler_Merci in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.3

A generic Entity handler.

The generic base implementation has a variety of overrides to workaround core's largely deficient entity handling.

Hierarchy

Expanded class hierarchy of EntityReference_SelectionHandler_Merci

1 string reference to 'EntityReference_SelectionHandler_Merci'
merci.inc in merci_entityref_behavior/plugins/selection/merci.inc

File

merci_entityref_behavior/plugins/selection/EntityReference_SelectionHandler_Merci.class.php, line 9

View source
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);
  }

  /**
   * Implements EntityReferenceHandler::getReferencableEntities().
   */
  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();

    //merci_api_validate_conflicts($entity_type, $entity, $field, $instance, $langcode, $items, &$errors);

    //merci_api_validate_restrictions($entity_type, $entity, $field, $instance, $langcode, $items, &$errors);
    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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityReference_SelectionHandler_Generic::buildEntityFieldQuery protected function Build an EntityFieldQuery to get referencable entities. 1
EntityReference_SelectionHandler_Generic::countReferencableEntities public function Implements EntityReferenceHandler::countReferencableEntities(). Overrides EntityReference_SelectionHandler::countReferencableEntities
EntityReference_SelectionHandler_Generic::ensureBaseTable public function Ensure a base table exists for the query.
EntityReference_SelectionHandler_Generic::entityFieldQueryAlter public function Implements EntityReferenceHandler::entityFieldQueryAlter(). Overrides EntityReference_SelectionHandler::entityFieldQueryAlter 5
EntityReference_SelectionHandler_Generic::getLabel public function Implements EntityReferenceHandler::getLabel(). Overrides EntityReference_SelectionHandler::getLabel 1
EntityReference_SelectionHandler_Generic::reAlterQuery protected function Helper method: pass a query to the alteration system again.
EntityReference_SelectionHandler_Generic::settingsForm public static function Implements EntityReferenceHandler::settingsForm(). Overrides EntityReference_SelectionHandler::settingsForm
EntityReference_SelectionHandler_Generic::validateAutocompleteInput public function Implements EntityReferenceHandler::validateAutocompleteInput(). Overrides EntityReference_SelectionHandler::validateAutocompleteInput
EntityReference_SelectionHandler_Generic::validateReferencableEntities public function Implements EntityReferenceHandler::validateReferencableEntities(). Overrides EntityReference_SelectionHandler::validateReferencableEntities
EntityReference_SelectionHandler_Generic::__construct protected function
EntityReference_SelectionHandler_Merci::getInstance public static function Implements EntityReferenceHandler::getInstance(). Overrides EntityReference_SelectionHandler_Generic::getInstance
EntityReference_SelectionHandler_Merci::getReferencableEntities public function Implements EntityReferenceHandler::getReferencableEntities(). Overrides EntityReference_SelectionHandler_Generic::getReferencableEntities