You are here

protected function SearchApiFieldTrait::getItemUrl in Search API 8

Retrieves an alter options array for linking the given value to its item.

Parameters

\Drupal\views\ResultRow $row: The Views result row object.

int $i: The index in this field's values for which the item link should be retrieved.

Return value

\Drupal\Core\Url|null The URL for the specified item, or NULL if it couldn't be found.

1 call to SearchApiFieldTrait::getItemUrl()
SearchApiFieldTrait::getItems in src/Plugin/views/field/SearchApiFieldTrait.php
Gets an array of items for the field.

File

src/Plugin/views/field/SearchApiFieldTrait.php, line 1288

Class

SearchApiFieldTrait
Provides a trait to use for Search API Views field handlers.

Namespace

Drupal\search_api\Plugin\views\field

Code

protected function getItemUrl(ResultRow $row, $i) {
  $this->valueIndex = $i;
  if ($entity = $this
    ->getEntity($row)) {
    if ($entity
      ->hasLinkTemplate('canonical')) {
      return $entity
        ->toUrl('canonical');
    }
  }
  if (!empty($row->_relationship_objects[NULL][0])) {
    try {
      return $this
        ->getIndex()
        ->getDatasource($row->search_api_datasource)
        ->getItemUrl($row->_relationship_objects[NULL][0]);
    } catch (SearchApiException $e) {
    }
  }
  return NULL;
}