You are here

public function SearchApiAbstractDataSourceController::getItemId in Search API 7

Retrieves the unique ID of an item.

Parameters

mixed $item: An item of this controller's type.

Return value

mixed Either the unique ID of the item, or NULL if none is available.

Throws

SearchApiDataSourceException If any error state was encountered.

Overrides SearchApiDataSourceControllerInterface::getItemId

3 methods override SearchApiAbstractDataSourceController::getItemId()
SearchApiCombinedEntityDataSourceController::getItemId in includes/datasource_multiple.inc
Retrieves the unique ID of an item.
SearchApiEntityDataSourceController::getItemId in includes/datasource_entity.inc
Retrieves the unique ID of an item.
SearchApiExternalDataSourceController::getItemId in includes/datasource_external.inc
Get the unique ID of an item.

File

includes/datasource.inc, line 518
Contains the SearchApiDataSourceControllerInterface as well as a default base class.

Class

SearchApiAbstractDataSourceController
Provides a default base class for datasource controllers.

Code

public function getItemId($item) {
  $id_info = $this
    ->getIdFieldInfo();
  $field = $id_info['key'];
  $wrapper = $this
    ->getMetadataWrapper($item);
  if (!isset($wrapper->{$field})) {
    return NULL;
  }
  $id = $wrapper->{$field}
    ->value();
  return $id ? $id : NULL;
}