Skip to content

Commit

Permalink
Merge pull request #2 from am-impact/master
Browse files Browse the repository at this point in the history
Keep trailing slash in mind when building new url
  • Loading branch information
lindseydiloreto committed Aug 11, 2015
2 parents 71a6a07 + 3617632 commit 84bec5b
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions languagelink/variables/LanguageLinkVariable.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function url($localeCode = 'en', $element = null)

// If localized element exists, return URL
if ($localeElement) {
return preg_replace('/__home__/', '', $baseUrl.$localeElement->uri);
return $this->_parseUrl($localeElement->uri, $localeCode);
} else {
return false;
}
Expand All @@ -35,10 +35,10 @@ public function url($localeCode = 'en', $element = null)

// Get page URI
$pageUri = craft()->request->path;

// If base URL exists, return URL
if ($baseUrl) {
return $baseUrl.$pageUri;
return $this->_parseUrl($pageUri, $localeCode);
} else {
return false;
}
Expand All @@ -63,5 +63,26 @@ private function _siteUrl($localeCode)
return false;
}
}


/**
* Parse URL.
*
* @param string $url
* @param string $localCode
*
* @return string
*/
private function _parseUrl($url, $localeCode) {
$baseUrl = $this->_siteUrl($localeCode);
$trailing = craft()->config->get('addTrailingSlashesToUrls') ? '/' : '';
$url = preg_replace('/__home__/', '', $url);

/* Homepage doesn't need trailingslash */
if( $url != '' ) {
$url = $url.$trailing;
}

return $baseUrl.$url;
}

}

0 comments on commit 84bec5b

Please sign in to comment.