You are here

public function SearchApiEntityDataSourceController::getIdFieldInfo in Search API 7

Returns information on the ID field for this controller's type.

Return value

array An associative array containing the following keys:

  • key: The property key for the ID field, as used in the item wrapper.
  • type: The type of the ID field. Has to be one of the types from search_api_field_types(). List types ("list<*>") are not allowed.

Throws

SearchApiDataSourceException If any error state was encountered.

Overrides SearchApiDataSourceControllerInterface::getIdFieldInfo

File

includes/datasource_entity.inc, line 59
Contains the SearchApiEntityDataSourceController class.

Class

SearchApiEntityDataSourceController
Represents a datasource for all entities known to the Entity API.

Code

public function getIdFieldInfo() {
  $properties = entity_get_property_info($this->entityType);
  if (!$this->idKey) {
    throw new SearchApiDataSourceException(t("Entity type @type doesn't specify an ID key.", array(
      '@type' => $this->entityInfo['label'],
    )));
  }
  if (empty($properties['properties'][$this->idKey]['type'])) {
    throw new SearchApiDataSourceException(t("Entity type @type doesn't specify a type for the @prop property.", array(
      '@type' => $this->entityInfo['label'],
      '@prop' => $this->idKey,
    )));
  }
  $type = $properties['properties'][$this->idKey]['type'];
  if (search_api_is_list_type($type)) {
    throw new SearchApiDataSourceException(t("Entity type @type uses list field @prop as its ID.", array(
      '@type' => $this->entityInfo['label'],
      '@prop' => $this->idKey,
    )));
  }
  if ($type == 'token') {
    $type = 'string';
  }
  return array(
    'key' => $this->idKey,
    'type' => $type,
  );
}