private function MenuLeaf::buildLinkUrl in Taxonomy Facets 8
1 call to MenuLeaf::buildLinkUrl()
File
- src/
MenuLeaf.php, line 56
Class
Namespace
Drupal\taxonomy_facetsCode
private function buildLinkUrl() {
$url = [];
$noTermFromCurrentVocabularyFound = TRUE;
$filters = null;
if ($this->filtersObject) {
$filters = $this->filtersObject
->getAppliedFilters();
}
if ($filters) {
// Loop trough applied filters.
foreach ($filters as $filter) {
// if filter is from current vocabulary than apply this leaf url alias
// instead of already applied filter
if ($filter
->getVocabularyId() == $this->vid) {
$obj = new \stdClass();
$obj->vid = $this->vid;
$obj->url = $this->urlAlias;
$url[] = $obj;
$noTermFromCurrentVocabularyFound = FALSE;
}
else {
$obj = new \stdClass();
$obj->vid = $filter
->getVocabularyId();
$obj->url = ltrim($filter
->url(), "/");
$url[] = $obj;
}
}
}
// If filters from this vocabulary were not in the applied filters than
// also apply the alias from the current leaf
if ($noTermFromCurrentVocabularyFound == TRUE) {
$obj = new \stdClass();
$obj->vid = $this->vid;
$obj->url = $this->urlAlias;
$url[] = $obj;
}
// @TODO replace 'listings' hard coded string with user configurable variable.
$this->linkUrl = $this
->getLanguagePrefix() . '/listings';
// Now order url aliases (filters) by vocabulary id so that we preserve
// order, so we don't end up with duplicate pages for same filter
// combinations.
usort($url, function ($a, $b) {
if ($a->vid == $b->vid) {
return 0;
}
return $a->vid < $b->vid ? -1 : 1;
});
foreach ($url as $u) {
$this->linkUrl .= '/' . $u->url;
}
}