You are here

public function SearchApiSortsManager::getActiveSort in Search API sorts 8

Returns the active sort field and order for a given search api display.

Parameters

\Drupal\search_api\Display\DisplayInterface $display: The display where the active sort should be returned for.

Return value

\Drupal\search_api_sorts\SortsField An object containing the field and order.

Overrides SearchApiSortsManagerInterface::getActiveSort

File

src/SearchApiSortsManager.php, line 68

Class

SearchApiSortsManager
Manages search api sorts.

Namespace

Drupal\search_api_sorts

Code

public function getActiveSort(DisplayInterface $display) {
  $order = strtolower($this->currentRequest
    ->get('order')) === 'desc' ? 'desc' : 'asc';
  $active_sort = new SortsField($this->currentRequest
    ->get('sort'), $order);

  // Allow altering the active sort (if there is an active sort).
  if ($active_sort
    ->getFieldName()) {
    $this->moduleHandler
      ->alter('search_api_sorts_active_sort', $active_sort, $display);
  }
  return $active_sort;
}