Skip to content

Commit

Permalink
Add support for SmartMap
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed May 5, 2018
1 parent efee210 commit 57dea04
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/fields/SmartMap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
namespace verbb\feedme\fields;

use verbb\feedme\base\Field;
use verbb\feedme\base\FieldInterface;
use verbb\feedme\helpers\DataHelper;

use Cake\Utility\Hash;

class SmartMap extends Field implements FieldInterface
{
// Properties
// =========================================================================

public static $name = 'SmartMap';
public static $class = 'doublesecretagency\smartmap\fields\Address';


// Templates
// =========================================================================

public function getMappingTemplate()
{
return 'feed-me/_includes/fields/smart-map';
}


// Public Methods
// =========================================================================

public function parseField()
{
$preppedData = [];

$fields = Hash::get($this->fieldInfo, 'fields');

foreach ($fields as $subFieldHandle => $subFieldInfo) {
$preppedData[$subFieldHandle] = DataHelper::fetchSimpleValue($this->feedData, $subFieldInfo);
}

return $preppedData;
}

}
2 changes: 2 additions & 0 deletions src/services/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use verbb\feedme\fields\MultiSelect;
use verbb\feedme\fields\Number;
use verbb\feedme\fields\RadioButtons;
use verbb\feedme\fields\SmartMap;
use verbb\feedme\fields\Table;
use verbb\feedme\fields\Tags;
use verbb\feedme\fields\Users;
Expand Down Expand Up @@ -112,6 +113,7 @@ public function getRegisteredFields()
MultiSelect::class,
Number::class,
RadioButtons::class,
SmartMap::class,
Table::class,
Tags::class,
Users::class,
Expand Down
58 changes: 58 additions & 0 deletions src/templates/_includes/fields/smart-map.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{# ------------------------ #}
{# Available Variables #}
{# ------------------------ #}
{# Attributes: #}
{# type, name, handle, instructions, attribute, default, feed, feedData #}
{# ------------------------ #}
{# Fields: #}
{# name, handle, instructions, feed, feedData, field, fieldClass #}
{# ------------------------ #}

{% import 'feed-me/_macros' as feedMeMacro %}
{% import '_includes/forms' as forms %}

{# Special case when inside another complex field (Matrix) #}
{% if parentPath is defined %}
{% set prefixPath = parentPath %}
{% else %}
{% set prefixPath = [handle] %}
{% endif %}

{% set classes = ['complex-field'] %}

<tr class="complex-field complex-field-header">
<td class="col-field" colspan="3">
<div class="field">
<div class="heading">
<label class="">{{ name }}</label>
</div>

<div class="additional-mapping-fields">
{% namespace 'fieldMapping[' ~ prefixPath | join('][') ~ ']' %}
<input type="text" name="field" value="{{ className(field) }}">
{% endnamespace %}
</div>
</div>
</td>
</tr>

{% for key, col in field.settings.layout %}
{% set nameLabel = craft.smartMap.labelFromHandle(key) %}
{% set instructionsHandle = handle ~ '[' ~ key ~ ']' %}

{% set path = prefixPath | merge ([ 'fields', key ]) %}

{% set default = default ?? {
type: 'text',
} %}

{% embed 'feed-me/_includes/fields/_base' %}
{% block additionalFieldSettings %}

{% endblock %}

{% block fieldSettings %}

{% endblock %}
{% endembed %}
{% endfor %}

0 comments on commit 57dea04

Please sign in to comment.