You are here

public function GlossaryAZWidgetOrderProcessor::sortResults in Search API AZ Glossary 8

Same name and namespace in other branches
  1. 8.4 src/Plugin/facets/processor/GlossaryAZWidgetOrderProcessor.php \Drupal\search_api_glossary\Plugin\facets\processor\GlossaryAZWidgetOrderProcessor::sortResults()
  2. 8.2 src/Plugin/facets/processor/GlossaryAZWidgetOrderProcessor.php \Drupal\search_api_glossary\Plugin\facets\processor\GlossaryAZWidgetOrderProcessor::sortResults()
  3. 8.3 src/Plugin/facets/processor/GlossaryAZWidgetOrderProcessor.php \Drupal\search_api_glossary\Plugin\facets\processor\GlossaryAZWidgetOrderProcessor::sortResults()

Orders results and return the new order of results.

Parameters

\Drupal\facets\Result\Result $a: First result which should be compared.

\Drupal\facets\Result\Result $b: Second result which should be compared.

Return value

int -1, 0, or 1 depending which result

Overrides SortProcessorInterface::sortResults

File

src/Plugin/facets/processor/GlossaryAZWidgetOrderProcessor.php, line 28

Class

GlossaryAZWidgetOrderProcessor
A processor that orders the results by display value.

Namespace

Drupal\search_api_glossary\Plugin\facets\processor

Code

public function sortResults(Result $a, Result $b) {
  $group_a = $this
    ->getResultGroup($a);
  $group_b = $this
    ->getResultGroup($b);
  if ($group_a == $group_b) {

    // Apply natural sorting within single group.
    return strnatcasecmp($a
      ->getRawValue(), $b
      ->getRawValue());
  }
  else {

    // Get the custom sort order from config.
    $sort_options_by_weight = $this
      ->sortConfigurationWeight($this
      ->getConfiguration()['sort']);
    return $sort_options_by_weight[$group_a] < $sort_options_by_weight[$group_b] ? -1 : 1;
  }
}