diff --git a/CHANGELOG.md b/CHANGELOG.md index 9218db1..f210864 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.0.2 - 2017-11-03 +### Fixed +- Fixed a bug where location searches would error if `orderBy` was not defined + ## 3.0.1 - 2017-11-03 ### Fixed - Fixed maps not rendering diff --git a/composer.json b/composer.json index c149ffa..3262b35 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "ether/simplemap", "description": "A beautifully simple Google Map field type.", - "version": "3.0.1", + "version": "3.0.2", "type": "craft-plugin", "license": "MIT", "minimum-stability": "dev", diff --git a/src/services/MapService.php b/src/services/MapService.php index f93d689..cf1f35b 100644 --- a/src/services/MapService.php +++ b/src/services/MapService.php @@ -202,12 +202,20 @@ public function modifyElementsQuery (ElementQueryInterface $query, $value) ] ); + if (!is_array($query->orderBy)) { + $oldOrderBy = $query->orderBy; + $query->orderBy = []; + } + if (array_key_exists('location', $value)) { $this->_searchLocation($query, $value); } else if (array_key_exists('distance', $query->orderBy)) { $this->_replaceOrderBy($query); } + if (isset($oldOrderBy)) + $query->orderBy = $oldOrderBy; + return; }