1 EntityReferenceSelectionHandlerViews.inc public EntityReferenceSelectionHandlerViews::getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0)

Implements EntityReferenceHandler::getReferencableEntities().

Overrides EntityReferenceSelectionHandlerInterface::getReferencableEntities

File

core/modules/entityreference/plugins/selection/EntityReferenceSelectionHandlerViews.inc, line 123

Class

EntityReferenceSelectionHandlerViews
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;
}