You are here

public function ContentEntity::getItemUrl in Search API 8

Retrieves a URL at which the item can be viewed on the web.

Parameters

\Drupal\Core\TypedData\ComplexDataInterface $item: An item of this datasource's type.

Return value

\Drupal\Core\Url|null Either an object representing the URL of the given item, or NULL if the item has no URL of its own.

Overrides DatasourcePluginBase::getItemUrl

File

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

Class

ContentEntity
Represents a datasource which exposes the content entities.

Namespace

Drupal\search_api\Plugin\search_api\datasource

Code

public function getItemUrl(ComplexDataInterface $item) {
  if ($entity = $this
    ->getEntity($item)) {
    if ($entity
      ->hasLinkTemplate('canonical')) {
      return $entity
        ->toUrl('canonical');
    }
  }
  return NULL;
}