You are here

public function EntityReference_SelectionHandler_Views::getReferencableEntities in Entity reference 7

Implements EntityReferenceHandler::getReferencableEntities().

Overrides EntityReference_SelectionHandler::getReferencableEntities

1 call to EntityReference_SelectionHandler_Views::getReferencableEntities()
EntityReference_SelectionHandler_Views::countReferencableEntities in plugins/selection/EntityReference_SelectionHandler_Views.class.php
Implements EntityReferenceHandler::countReferencableEntities().

File

plugins/selection/EntityReference_SelectionHandler_Views.class.php, line 126

Class

EntityReference_SelectionHandler_Views
Entity handler for Views.

Code

public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
  $display_name = $this->field['settings']['handler_settings']['view']['display_name'];
  $args = $this
    ->handleArgs($this->field['settings']['handler_settings']['view']['args']);
  $result = array();
  if ($this
    ->initializeView($match, $match_operator, $limit)) {

    // Get the results.
    $result = $this->view
      ->execute_display($display_name, $args);
  }
  $return = array();
  if ($result) {
    $target_type = $this->field['settings']['target_type'];
    $entities = entity_load($target_type, array_keys($result));
    foreach ($entities as $entity) {
      list($id, , $bundle) = entity_extract_ids($target_type, $entity);
      $return[$bundle][$id] = $result[$id];
    }
  }
  return $return;
}