function SelectedFilters::__construct in Taxonomy Facets 8
File
- src/
SelectedFilters.php, line 23
Class
Namespace
Drupal\taxonomy_facetsCode
function __construct($term_names = array()) {
// Set filters
foreach ($term_names as $term_name) {
if ($tid = self::getTermIdFromUrlAlias($term_name)) {
$this->terms[] = \Drupal\taxonomy\Entity\Term::load($tid);
}
}
// Sort by vocabulary id so that we always get same order of filters, to avoid
// duplicate urls for the same page.
if ($this->terms) {
usort($this->terms, function ($a, $b) {
if ((int) $a
->id() == (int) $b
->id()) {
return 0;
}
if ((int) $a
->id() < (int) $b
->id()) {
return -1;
}
else {
return 1;
}
});
}
}