You are here

public function EntityReference_SelectionHandler_DDF::getReferencableEntities in Dynamic dependent fields 7

Implements EntityReferenceHandler::getReferencableEntities().

Overrides EntityReference_SelectionHandler_Views::getReferencableEntities

File

modules/ddf_entityreference/plugins/selection/EntityReference_SelectionHandler_DDF.class.php, line 87

Class

EntityReference_SelectionHandler_DDF
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']);
  $args = $this
    ->handleDynamicArgs($args);
  $result = array();
  if ($this
    ->initializeView($match, $match_operator, $limit)) {

    // Get the results.
    $result = $this->view
      ->execute_display($display_name, !array_filter($args) ? array() : $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;
}