Skip to content

Instantly share code, notes, and snippets.

@engram-design
Last active February 27, 2017 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save engram-design/425b408cb876ece0d7ead8b7dbcac134 to your computer and use it in GitHub Desktop.
Save engram-design/425b408cb876ece0d7ead8b7dbcac134 to your computer and use it in GitHub Desktop.
SmartMap Feed Me 2
{% 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 %}
<?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;
}
}
<?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