public function DisplayValueWidgetOrderProcessor::sortResults in Facets 8
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/ DisplayValueWidgetOrderProcessor.php, line 66
Class
- DisplayValueWidgetOrderProcessor
- A processor that orders the results by display value.
Namespace
Drupal\facets\Plugin\facets\processorCode
public function sortResults(Result $a, Result $b) {
// Get the transliterate values only once.
if (!isset($a->transliterateDisplayValue)) {
$a->transliterateDisplayValue = $this->transliteration
->removeDiacritics($a
->getDisplayValue());
}
if (!isset($b->transliterateDisplayValue)) {
$b->transliterateDisplayValue = $this->transliteration
->removeDiacritics($b
->getDisplayValue());
}
// Return the sort value.
if ($a->transliterateDisplayValue == $b->transliterateDisplayValue) {
return 0;
}
return strnatcasecmp($a->transliterateDisplayValue, $b->transliterateDisplayValue);
}