You are here

public function OgSubspacesSelectionHandler::getReferencableEntities in Open Atrium Core 7.2

Implements EntityReferenceHandler::getReferencableEntities().

Overrides EntityReference_SelectionHandler_Generic::getReferencableEntities

File

plugins/entityreference/selection/OgSubspacesSelectionHandler.class.php, line 78
Code for OG Subspaces selection handler

Class

OgSubspacesSelectionHandler
OG Subspaces selection handler for OA.

Code

public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
  $options = array();
  $entity_type = $this->field['settings']['target_type'];
  $query = $this
    ->buildEntityFieldQuery($match, $match_operator);
  if ($limit > 0) {
    $query
      ->range(0, $limit);
  }
  $results = $query
    ->execute();
  if (!empty($results[$entity_type])) {

    // call the OA helper function to get the title of nodes quickly
    $titles = oa_core_get_titles(array_keys($results[$entity_type]), '', '', array(
      'id',
      'title',
      'type',
    ), TRUE, $limit);
    if (!empty($titles['titles'])) {
      foreach ($titles['titles'] as $key => $title) {
        $options[$titles['types'][$key]][$titles['ids'][$key]] = $title;
      }
    }
  }
  return $options;
}