Skip to content

Commit

Permalink
Fix lack of translation for Row layout
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Feb 18, 2017
1 parent 716014c commit e72fd7e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 249 deletions.
244 changes: 0 additions & 244 deletions supertable/integrations/feedme/fields/SuperTableFeedMeFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,247 +179,3 @@ public function postFieldData($element, $field, &$data, $handle)

}












/*class SuperTableFeedMeFieldType extends BaseFeedMeFieldType
{
// Templates
// =========================================================================
public function getMappingTemplate()
{
return 'supertable/_integrations/feedme/fields/supertable';
}
// Public Methods
// =========================================================================
public function prepFieldData($element, $field, $fieldData, $handle, $options)
{
$preppedData = array();
$sortedData = array();
$data = Hash::get($fieldData, 'data');
if (empty($data)) {
return;
}
// Store the fields for this Super Table field - can't use the fields service due to context
$blockTypeFields = array();
$blockTypes = craft()->superTable->getBlockTypesByFieldId($field->id);
$blockType = $blockTypes[0]; // Super Table only ever has one Block Type
foreach ($blockType->getFields() as $f) {
$blockTypeFields[$f->handle] = $f;
}
// Data will be provided as:
// blocktypeid = [
// fieldHandle = [
// data
// ]
// ]
//
// Don't forget, Super Table fields only have one blockTypeId, so grab that separately
// and set $data to our actual data we want to process
$dataKeys = array_keys($data);
$blockTypeId = $dataKeys[0];
$data = $data[$blockTypeId];
$optionsArray = array();
$fieldsArray = array();
$flatten = Hash::flatten($data);
foreach ($flatten as $keyedIndex => $value) {
$tempArray = explode('.', $keyedIndex);
// Save field options and nested fields for later - they're a special case
if (strstr($keyedIndex, '.options.')) {
FeedMeArrayHelper::arraySet($optionsArray, $tempArray, $value);
} else if (strstr($keyedIndex, '.fields.')) {
FeedMeArrayHelper::arraySet($fieldsArray, $tempArray, $value);
} else {
//preg_match_all('/data.(\d*)/', $keyedIndex, $blockKeys);
//$blockKey = $blockKeys[1];
// Check if we're importing a single row into Super Table
//if (!$blockKey) {
//$tempArray[] = 0;
//$blockKey = 0;
//}
// What type of field are we importing? Some fields require specifics dat (Elements = array)
$field = $blockTypeFields[$tempArray[0]];
// Element fields need an array - but we actually check for data in the format:
if ($field->type == 'Assets') {
// If we're missing a 'fieldHandle.data.0.0' pattern, fix it
if (!preg_match('/data.(\d*\.\d*)/', $keyedIndex)) {
array_splice($tempArray, 2, 0, 0);
}
// And another slightly special case - not sure why, but not going to upset things
// until we can fully unit-test all these cases - nightmare!
if (preg_match('/data.(\d*\.\d*\.\d*)/', $keyedIndex)) {
unset($tempArray[2]);
$tempArray = array_values($tempArray); // re-base keys
}
} else {
// We're dealing with a regular field - but the trick here is to check if we're
// importing a single Super Table Row - we still need to treat it like an array
// ie - we get data delivered as 'fieldHandle.data' - missing a '0' at the end
if (!preg_match('/data.(\d*)/', $keyedIndex)) {
array_splice($tempArray, 2, 0, 0);
}
}
// Remove the index from inside [data], to the front
array_splice($tempArray, 0, 0, $tempArray[2]);
unset($tempArray[3]);
$tempArray = array_values($tempArray); // re-base keys
// Check if we're importing a single row into Super Table
//if (!$blockKey) {
// But, important to check what sort of field we're importing into. For instance
// Element fields actually require an array of elements, so we don't want to mess that up
echo "<pre>";
print_r($tempArray);
echo "</pre>";
//}
FeedMeArrayHelper::arraySet($sortedData, $tempArray, $value);
}
}
// Now a special case for field options and nested fields. Because of the way field-mapping stores them,
// we need to loop through and apply across all blocks of this type. This also makes field-processing easier
foreach ($sortedData as $blockOrder => $blockData) {
foreach ($blockData as $blockHandle => $innerData) {
$additionalData = array();
// Get field options or nested fields
$optionData = Hash::get($optionsArray, $blockHandle);
$fieldData = Hash::get($fieldsArray, $blockHandle);
if ($optionData) {
$additionalData = Hash::merge($additionalData, $optionData);
}
if ($fieldData) {
//$additionalData = Hash::merge($additionalData, $fieldData);
}
$sortedData[$blockOrder][$blockHandle] = Hash::merge($innerData, $additionalData);
}
}
echo "<pre>";
print_r($flatten);
echo "</pre>";
echo "<pre>";
print_r($sortedData);
echo "</pre>";
// Sort by the new ordering we've set
ksort($sortedData);
// Store the fields for this Matrix - can't use the fields service due to context
$blockTypes = craft()->matrix->getBlockTypesByFieldId($field->id, 'handle');
$count = 0;
$allPreppedFieldData = array();
foreach ($sortedData as $sortKey => $sortData) {
foreach ($sortData as $blockHandle => $blockFieldData) {
foreach ($blockFieldData as $blockFieldHandle => $blockFieldContent) {
// Get the Matrix-contexted field for our regular field-prepping function
$blockType = $blockTypes[$blockHandle];
foreach ($blockType->getFields() as $f) {
if ($f->handle == $blockFieldHandle) {
$subField = $f;
}
}
if (!isset($subField)) {
continue;
}
$fieldOptions = array(
'field' => $subField,
);
// Parse this inner-field's data, just like a regular field
$parsedData = craft()->feedMe_fields->prepForFieldType(null, $blockFieldContent, $blockFieldHandle, $fieldOptions);
if ($parsedData) {
// Special-case for inner table - not a great solution at the moment, needs to be more flexible
if ($subField->type == 'Table') {
foreach ($parsedData as $i => $tableFieldRow) {
$next = reset($tableFieldRow);
if (!is_array($next)) {
$tableFieldRow = array($i => $tableFieldRow);
}
foreach ($tableFieldRow as $j => $tableFieldColumns) {
foreach ($tableFieldColumns as $k => $tableFieldColumn) {
$allPreppedFieldData[$k][$blockHandle][$blockFieldHandle][$j][$sortKey] = $tableFieldColumn;
}
}
}
} else {
$allPreppedFieldData[$sortKey][$blockHandle][$blockFieldHandle] = $parsedData;
}
}
}
}
}
// Now we've got a bit more sane data - its a simple (regular) import
if ($allPreppedFieldData) {
foreach ($allPreppedFieldData as $key => $preppedBlockFieldData) {
foreach ($preppedBlockFieldData as $blockHandle => $preppedFieldData) {
$preppedData['new'.($count+1)] = array(
'type' => $blockHandle,
'order' => ($count+1),
'enabled' => true,
'fields' => $preppedFieldData,
);
$count++;
}
}
}
return $preppedData;
}
public function postFieldData($element, $field, &$data, $handle)
{
}
}*/
7 changes: 5 additions & 2 deletions supertable/templates/fields.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
<tr data-id="">
<td class="thin rowHeader">
<span class="heading-text {% if field.required %}required{% endif %}">
{{ field.getField().name }}
{% if field.getField().instructions %}<span class="info">{{ field.getField().instructions }}</span>{% endif %}
{{ field.getField().name | t }}

{% if field.getField().instructions %}
<span class="info">{{ field.getField().instructions | t }}</span>
{% endif %}
</span>
</td>

Expand Down
8 changes: 5 additions & 3 deletions supertable/templates/tableInput.html
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<th scope="col" class="col-header" {% if width is defined and width %}style="width: {{ width }}"{% endif %}>
<span class="heading-text {% if field.required %}required{% endif %}">
{{ field.name|t }} {% if field.instructions %}<span class="info">{{ field.instructions|t }}</span>{% endif %}
{{ field.name | t }} {% if field.instructions %}<span class="info">{{ field.instructions | t }}</span>{% endif %}
</span>
</th>
{% endfor %}
Expand All @@ -51,7 +51,7 @@
{% set blocks = [blocks] %}
{% endif %}
{% endif %}

{% for block in blocks %}
{% set blockId = block.id %}

Expand All @@ -64,7 +64,7 @@
<td class="hidden">
<input type="hidden" name="{{ name }}[{{ blockId }}][type]" value="{{ block.getType() }}">
</td>

{% include "supertable/fields" with {
namespace: name~'['~blockId~'][fields]',
element: block,
Expand All @@ -87,3 +87,5 @@
<div class="btn add icon" {% if settings.staticField %}style="display: none;"{% endif %}>{{ settings.selectionLabel | default("Add a row") | t }}</div>
</div>
</div>


0 comments on commit e72fd7e

Please sign in to comment.