Last active
February 27, 2017 11:33
-
-
Save engram-design/425b408cb876ece0d7ead8b7dbcac134 to your computer and use it in GitHub Desktop.
SmartMap Feed Me 2
This file contains hidden or 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
{% if field.settings %} | |
{% set smartMapSubfields = [] %} | |
{% for subfield,settings in field.settings.layout %} | |
{% if settings.enable %} | |
{% set smartMapSubfields = smartMapSubfields|merge([subfield]) %} | |
{% endif %} | |
{% endfor %} | |
{% else %} | |
{% set smartMapSubfields = ['street1','street2','city','state','zip','country','lat','lng'] %} | |
{% endif %} | |
{% for subfield in smartMapSubfields %} | |
{% set optionLabel = field.name ~ ' (' ~ craft.smartMap.labelFromHandle(subfield) ~ ')' %} | |
{% set optionLabelHandle = field.handle ~ '[' ~ subfield ~ ']' %} | |
{% set optionHandle = field.handle ~ '--' ~ subfield %} | |
<tr> | |
<td class="col-field"> | |
<div class="field"> | |
<div class="heading"> | |
<label>{{ optionLabel }}</label> | |
<div class="instructions"> | |
<code>{{ optionLabelHandle }}</code> | |
</div> | |
</div> | |
</div> | |
</td> | |
<td class="col-map"> | |
{% namespace 'fieldMapping' %} | |
{{ forms.selectField({ | |
id: optionHandle, | |
name: optionHandle, | |
value: feed.fieldMapping[optionHandle] ?? '', | |
options: feedData, | |
}) }} | |
{% endnamespace %} | |
</td> | |
<td class="col-default"> | |
<div class="default-fields"> | |
</div> | |
</td> | |
</tr> | |
{% endfor %} |
This file contains hidden or 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
<?php | |
namespace Craft; | |
class SmartMap_AddressFeedMeFieldType extends BaseFeedMeFieldType | |
{ | |
// Templates | |
// ========================================================================= | |
public function getMappingTemplate() | |
{ | |
return 'smartmap/_integrations/feedme/fields/smartmap_address'; | |
} | |
// Public Methods | |
// ========================================================================= | |
public function prepFieldData($element, $field, $fieldData, $handle, $options) | |
{ | |
// Initialize content array | |
$content = array(); | |
$data = $fieldData['data']; | |
foreach ($data as $subfieldHandle => $subfieldData) { | |
// Set value to subfield of correct address array | |
$content[$subfieldHandle] = $subfieldData['data']; | |
} | |
// Return data | |
return $content; | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace Craft; | |
class SmartMapPlugin extends BasePlugin | |
{ | |
public function init() | |
{ | |
Craft::import('plugins.smartmap.integrations.feedme.fields.SmartMap_AddressFeedMeFieldType'); | |
} | |
// =========================================================================== // | |
// For compatibility with Feed Me plugin (v2.0.0) | |
public function registerFeedMeFieldTypes() | |
{ | |
return array( | |
new SmartMap_AddressFeedMeFieldType(), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment