Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrestoffe committed Nov 18, 2020
2 parents 394d918 + 205eeea commit 0d7bd3d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .craftplugin
@@ -1 +1 @@
{"pluginName":"Locale Redirector","pluginDescription":"Automatically redirect visitors to their preferred language","pluginVersion":"1.5.1","pluginAuthorName":"Pierre Stoffe","pluginVendorName":"pierrestoffe","pluginAuthorUrl":"https://pierrestoffe.be","pluginAuthorGithub":"pierrestoffe","codeComments":"yes","pluginComponents":["services"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"}
{"pluginName":"Locale Redirector","pluginDescription":"Automatically redirect visitors to their preferred language","pluginVersion":"1.5.2","pluginAuthorName":"Pierre Stoffe","pluginVendorName":"pierrestoffe","pluginAuthorUrl":"https://pierrestoffe.be","pluginAuthorGithub":"pierrestoffe","codeComments":"yes","pluginComponents":["services"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [Unreleased]

## [1.5.2] - 2020-11-18

### Fixed
- Fixed edge case of $defaultEntryId, when an entry exists in a Site but is disabled

## [1.5.1] - 2020-11-06

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -2,7 +2,7 @@
"name": "pierrestoffe/craft-language-redirector",
"description": "Automatically redirect visitors to their preferred language",
"type": "craft-plugin",
"version": "1.5.1",
"version": "1.5.2",
"keywords": [
"craft",
"cms",
Expand Down
16 changes: 6 additions & 10 deletions src/services/LanguageRedirectorService.php
Expand Up @@ -199,20 +199,16 @@ public function getTargetElement(string $language = null, string $group = null)
return null;
}

$targetElementFound = true;
$targetElement = Craft::$app->elements->getElementById($currentElement->getId(), null, $targetSite->id);

if (null === $targetElement && null !== $defaultEntryId) {
$defaultElement = Craft::$app->elements->getElementById($defaultEntryId, null, $targetSite->id);
$targetElement = $defaultElement;
}

if (null === $targetElement) {
return null;
// If element is not enabled for this site
if (null === $targetElement || (false == $targetElement->enabledForSite && null === $this->_getLanguageFromQueryParameter())) {
$targetElementFound = false;
}

// If element is not enabled for this site
if (false == $targetElement->enabledForSite && null === $this->_getLanguageFromQueryParameter()) {
return null;
if (false === $targetElementFound && null !== $defaultEntryId) {
$targetElement = Craft::$app->elements->getElementById($defaultEntryId, null, $targetSite->id);
}

return $targetElement;
Expand Down
1 change: 1 addition & 0 deletions src/variables/LanguageSwitcherVariable.php
Expand Up @@ -26,6 +26,7 @@ class LanguageSwitcherVariable
* Get the URLs of all languages.
*
* @param array|null $urlOverrides
* @param string $group
*
* @return array
*/
Expand Down

0 comments on commit 0d7bd3d

Please sign in to comment.