Skip to content

Commit

Permalink
BUG Fix invalid locale being set for domain mode
Browse files Browse the repository at this point in the history
Fixes #419
  • Loading branch information
Damian Mooyman committed Jun 6, 2018
1 parent 353312e commit e02691a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/Middleware/DetectLocaleMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,10 @@ protected function getDomainLocale()

// If the current domain has exactly one locale, the locale is non-ambiguous
$locales = Locale::getCached()->filter('DomainID', $domainObj->ID);
if ($locales->count() === 1) {
return $locales->first();
/** @var Locale $localeObject */
$localeObject = $locales->first();
if ($localeObject) {
return $localeObject->getLocale();
}

return null;
Expand Down
15 changes: 11 additions & 4 deletions src/State/FluentState.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace TractorCow\Fluent\State;

use InvalidArgumentException;
use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Core\Injector\Injector;

Expand All @@ -20,9 +21,9 @@ class FluentState
protected $locale;

/**
* Current domain
* Current domain, if set
*
* @var string
* @var string|null
*/
protected $domain;

Expand Down Expand Up @@ -58,14 +59,17 @@ public function getLocale()
*/
public function setLocale($locale)
{
if (empty($locale) || !is_string($locale)) {
throw new InvalidArgumentException("Invalid locale");
}
$this->locale = $locale;
return $this;
}

/**
* Get the current domain code
*
* @return string
* @return string|null
*/
public function getDomain()
{
Expand All @@ -75,11 +79,14 @@ public function getDomain()
/**
* Set the current domain code
*
* @param string $domain
* @param string|null $domain
* @return $this
*/
public function setDomain($domain)
{
if ($domain && !is_string($domain)) {
throw new InvalidArgumentException("Invalid domain");
}
$this->domain = $domain;
return $this;
}
Expand Down

0 comments on commit e02691a

Please sign in to comment.