-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to save map with only an address
- Loading branch information
Showing
6 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace ether\simplemap\fields; | ||
|
||
use ether\simplemap\services\MapService; | ||
use yii\validators\Validator; | ||
|
||
class MapValidator extends Validator { | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function validateValue ($value) | ||
{ | ||
if (!is_null($value->lat) && !is_null($value->lng)) | ||
return null; | ||
|
||
if (!is_null($value->address)) { | ||
$addressToLatLng = MapService::getLatLngFromAddress($value['address']); | ||
if (is_null($addressToLatLng)) { | ||
return [ | ||
\Craft::t( | ||
'simplemap', | ||
'Missing Lat/Lng or valid address' | ||
), | ||
[] | ||
]; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
return [ | ||
\Craft::t( | ||
'simplemap', | ||
'Missing Lat/Lng' | ||
), | ||
[] | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters