From e72fd7e2159207a5ab569539f4eeacf2b0715633 Mon Sep 17 00:00:00 2001 From: Josh Crawford Date: Sat, 18 Feb 2017 14:33:18 +1100 Subject: [PATCH] Fix lack of translation for Row layout --- .../fields/SuperTableFeedMeFieldType.php | 244 ------------------ supertable/templates/fields.html | 7 +- supertable/templates/tableInput.html | 8 +- 3 files changed, 10 insertions(+), 249 deletions(-) mode change 100755 => 100644 supertable/templates/tableInput.html diff --git a/supertable/integrations/feedme/fields/SuperTableFeedMeFieldType.php b/supertable/integrations/feedme/fields/SuperTableFeedMeFieldType.php index 50b8db1..e1f1223 100644 --- a/supertable/integrations/feedme/fields/SuperTableFeedMeFieldType.php +++ b/supertable/integrations/feedme/fields/SuperTableFeedMeFieldType.php @@ -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 "
";
-                print_r($tempArray);
-                echo "
"; - - //} - - 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 "
";
-        print_r($flatten);
-        echo "
"; - - echo "
";
-        print_r($sortedData);
-        echo "
"; - - - // 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) - { - - } - -}*/ \ No newline at end of file diff --git a/supertable/templates/fields.html b/supertable/templates/fields.html index 51d6cb5..46bbaf2 100644 --- a/supertable/templates/fields.html +++ b/supertable/templates/fields.html @@ -8,8 +8,11 @@ - {{ field.getField().name }} - {% if field.getField().instructions %}{{ field.getField().instructions }}{% endif %} + {{ field.getField().name | t }} + + {% if field.getField().instructions %} + {{ field.getField().instructions | t }} + {% endif %} diff --git a/supertable/templates/tableInput.html b/supertable/templates/tableInput.html old mode 100755 new mode 100644 index 9cb6ea2..9075258 --- a/supertable/templates/tableInput.html +++ b/supertable/templates/tableInput.html @@ -32,7 +32,7 @@ - {{ field.name|t }} {% if field.instructions %}{{ field.instructions|t }}{% endif %} + {{ field.name | t }} {% if field.instructions %}{{ field.instructions | t }}{% endif %} {% endfor %} @@ -51,7 +51,7 @@ {% set blocks = [blocks] %} {% endif %} {% endif %} - + {% for block in blocks %} {% set blockId = block.id %} @@ -64,7 +64,7 @@ - + {% include "supertable/fields" with { namespace: name~'['~blockId~'][fields]', element: block, @@ -87,3 +87,5 @@
{{ settings.selectionLabel | default("Add a row") | t }}
+ +