|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Maps for Craft CMS |
| 4 | + * |
| 5 | + * @link https://ethercreative.co.uk |
| 6 | + * @copyright Copyright (c) 2024 Ether Creative |
| 7 | + */ |
| 8 | + |
| 9 | +namespace ether\simplemap\acfadapters; |
| 10 | + |
| 11 | +use craft\base\FieldInterface; |
| 12 | +use craft\wpimport\BaseAcfAdapter; |
| 13 | +use ether\simplemap\fields\MapField; |
| 14 | + |
| 15 | +/** |
| 16 | + * Class GoogleMap |
| 17 | + * |
| 18 | + * @author Ether Creative |
| 19 | + * @author Brandon Kelly |
| 20 | + * @package ether\simplemap\acfadapters |
| 21 | + */ |
| 22 | +class GoogleMap extends BaseAcfAdapter |
| 23 | +{ |
| 24 | + public static function type(): string |
| 25 | + { |
| 26 | + return 'google_map'; |
| 27 | + } |
| 28 | + |
| 29 | + public function create(array $data): FieldInterface |
| 30 | + { |
| 31 | + $field = new MapField(); |
| 32 | + if ($data['center_lat']) { |
| 33 | + $field->lat = $data['center_lat']; |
| 34 | + } |
| 35 | + if ($data['center_lng']) { |
| 36 | + $field->lng = $data['center_lng']; |
| 37 | + } |
| 38 | + if ($data['zoom']) { |
| 39 | + $field->zoom = $data['zoom']; |
| 40 | + } |
| 41 | + return $field; |
| 42 | + } |
| 43 | + |
| 44 | + public function normalizeValue(mixed $value, array $data): mixed |
| 45 | + { |
| 46 | + return [ |
| 47 | + 'address' => $value['address'], |
| 48 | + 'lat' => $value['lat'], |
| 49 | + 'lng' => $value['lng'], |
| 50 | + 'zoom' => $value['zoom'], |
| 51 | + 'parts' => [ |
| 52 | + 'number' => $value['street_number'], |
| 53 | + 'address' => $value['street_name'], |
| 54 | + 'city' => $value['city'], |
| 55 | + 'postcode' => $value['post_code'], |
| 56 | + 'state' => $value['state'], |
| 57 | + 'country' => $value['country'], |
| 58 | + 'administrative_area_level_1' => $value['state'], |
| 59 | + 'locality' => $value['city'], |
| 60 | + 'postal_code' => $value['post_code'], |
| 61 | + 'route' => $value['street_name'], |
| 62 | + 'street_number' => $value['street_number'], |
| 63 | + ], |
| 64 | + ]; |
| 65 | + } |
| 66 | +} |
0 commit comments