diff --git a/CHANGELOG.md b/CHANGELOG.md index e03c181..df6d027 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.5.2 - 2019-06-20 +### Improved +- FeedMe can now import the individual map parts + ## 3.5.1 - 2019-06-20 ### Added - Maps can now populate address and lat/lng data based off only a postcode diff --git a/composer.json b/composer.json index 1df842c..8d7abef 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "ether/simplemap", "description": "A beautifully simple Map field type for Craft CMS 3", - "version": "3.5.1", + "version": "3.5.2", "type": "craft-plugin", "license": "MIT", "minimum-stability": "dev", diff --git a/src/elements/Map.php b/src/elements/Map.php index 2a6fd5f..b3eb543 100644 --- a/src/elements/Map.php +++ b/src/elements/Map.php @@ -69,13 +69,16 @@ public function __construct (array $config = []) if ($this->address === null) $this->address = ''; - if ($this->parts && !is_array($this->parts)) - $this->parts = Json::decodeIfJson($this->parts); - - if (Parts::isLegacy($this->parts)) - $this->parts = new PartsLegacy($this->parts); - else - $this->parts = new Parts($this->parts); + if (!($this->parts instanceof Parts)) + { + if ($this->parts && !is_array($this->parts)) + $this->parts = Json::decodeIfJson($this->parts); + + if (Parts::isLegacy($this->parts)) + $this->parts = new PartsLegacy($this->parts); + else + $this->parts = new Parts($this->parts); + } $this->distance = SimpleMap::getInstance()->map->getDistance($this); } diff --git a/src/integrations/feedme/FeedMeMaps.php b/src/integrations/feedme/FeedMeMaps.php index e4acc61..a8223c8 100644 --- a/src/integrations/feedme/FeedMeMaps.php +++ b/src/integrations/feedme/FeedMeMaps.php @@ -52,10 +52,22 @@ public function parseField () return null; foreach ($fields as $subFieldHandle => $subFieldInfo) + { + if ($subFieldHandle === 'parts') { + foreach ($subFieldInfo as $handle => $info) + $preppedData[$subFieldHandle][$handle] = DataHelper::fetchValue( + $this->feedData, + $info + ); + + continue; + } + $preppedData[$subFieldHandle] = DataHelper::fetchValue( $this->feedData, $subFieldInfo ); + } if (isset($preppedData['parts'])) $preppedData['parts'] = new Parts($preppedData['parts']); diff --git a/src/templates/_feedme-mapping.twig b/src/templates/_feedme-mapping.twig index 53d178e..278f08d 100644 --- a/src/templates/_feedme-mapping.twig +++ b/src/templates/_feedme-mapping.twig @@ -40,14 +40,30 @@ lat: 'Latitude'|t('simplemap'), lng: 'Longitude'|t('simplemap'), zoom: 'Zoom'|t('simplemap'), - address: 'Address'|t('simplemap'), + address: 'Full Address'|t('simplemap'), + 'parts.number': 'Number'|t('simplemap'), + 'parts.address': 'Address'|t('simplemap'), + 'parts.city': 'City'|t('simplemap'), + 'parts.postcode': 'Postcode'|t('simplemap'), + 'parts.county': 'County'|t('simplemap'), + 'parts.state': 'State'|t('simplemap'), + 'parts.country': 'Country'|t('simplemap'), } %} {% for key, col in simpleMapSubfields %} + {% set splitKey = '.' in key %} + {% set subKey = null %} + + {% if splitKey %} + {% set key = key|split('.') %} + {% set subKey = key[1] %} + {% set key = key[0] %} + {% endif %} + {% set nameLabel = col %} - {% set instructionsHandle = handle ~ '[' ~ key ~ ']' %} + {% set instructionsHandle = handle ~ '[' ~ key ~ ']' ~ (subKey ? '[' ~ subKey ~ ']') %} - {% set path = prefixPath | merge ([ 'fields', key ]) %} + {% set path = prefixPath | merge ([ 'fields', key, subKey ]|filter) %} {% set default = default ?? { type: 'text',