You are here

public function ContentEntity::getItemId in Search API 8

Retrieves the unique ID of an object from this datasource.

Parameters

\Drupal\Core\TypedData\ComplexDataInterface $item: An object from this datasource.

Return value

string|null The datasource-internal, unique ID of the item. Or NULL if the given item is no valid item of this datasource.

Overrides DatasourceInterface::getItemId

File

src/Plugin/search_api/datasource/ContentEntity.php, line 677

Class

ContentEntity
Represents a datasource which exposes the content entities.

Namespace

Drupal\search_api\Plugin\search_api\datasource

Code

public function getItemId(ComplexDataInterface $item) {
  if ($entity = $this
    ->getEntity($item)) {
    $enabled_bundles = $this
      ->getBundles();
    if (isset($enabled_bundles[$entity
      ->bundle()])) {
      return $entity
        ->id() . ':' . $entity
        ->language()
        ->getId();
    }
  }
  return NULL;
}