diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e7a2a7..70d4a01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +#### 0.3.8 + +- Ensure Craft 2.3.2615 is minimum required version. + #### 0.3.7 - Added relations support, thanks to [joshangell](https://github.com/joshangell). diff --git a/README.md b/README.md index 8656fb9..6dc2bcd 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,4 @@ Super Table requires a minimum of Craft 2.3.2615 in order to function. ## Changelog -#### 0.3.8 - -- Ensure Craft 2.3.2615 is minimum required version. - - -[View Full Changelog](https://github.com/engram-design/SuperTable/blob/master/CHANGELOG.md) +[View JSON Changelog](https://github.com/engram-design/SuperTable/blob/master/changelog.json) diff --git a/changelog.json b/changelog.json new file mode 100644 index 0000000..f3b5fe8 --- /dev/null +++ b/changelog.json @@ -0,0 +1,13 @@ +[ + { + "version": "0.4.0", + "downloadUrl": "https://github.com/engram-design/SuperTable/archive/0.4.0.zip", + "date": "2015-12-01 19:45:00", + "notes": [ + "[Added] Craft 2.5 support, including release feed and icons.", + "[Added] Support for [Feed Me](https://github.com/engram-design/FeedMe).", + "[Added] Support for [Export](https://github.com/boboldehampsink/Export).", + "[Fixed] Labels in Row Layout are now top-aligned." + ] + } +] diff --git a/supertable/SuperTablePlugin.php b/supertable/SuperTablePlugin.php index 43b4d80..e77146b 100755 --- a/supertable/SuperTablePlugin.php +++ b/supertable/SuperTablePlugin.php @@ -3,9 +3,9 @@ class SuperTablePlugin extends BasePlugin { - /* -------------------------------------------------------------- - * PLUGIN INFO - * ------------------------------------------------------------ */ + // ========================================================================= + // PLUGIN INFO + // ========================================================================= public function getName() { @@ -17,6 +17,11 @@ public function getVersion() return '0.3.8'; } + public function getSchemaVersion() + { + return '1.0.0'; + } + public function getDeveloper() { return 'S. Group'; @@ -27,25 +32,56 @@ public function getDeveloperUrl() return 'http://sgroup.com.au'; } - public function onAfterInstall() - { - $minBuild = '2615'; + public function getPluginUrl() + { + return 'https://github.com/engram-design/SuperTable'; + } - if (craft()->getBuild() < $minBuild) { - craft()->plugins->disablePlugin($this->getClassHandle()); + public function getDocumentationUrl() + { + return $this->getPluginUrl() . '/blob/master/README.md'; + } - craft()->plugins->uninstallPlugin($this->getClassHandle()); + public function getReleaseFeedUrl() + { + return $this->getPluginUrl() . '/blob/master/changelog.json'; + } - craft()->userSession->setError(Craft::t('{plugin} only works on Craft build {build} or higher', array( - 'plugin' => $this->getName(), - 'build' => $minBuild, - ))); + public function onBeforeInstall() + { + // Craft 2.3.2615 getFieldsForElementsQuery() + if (version_compare(craft()->getVersion() . '.' . craft()->getBuild(), '2.3.2615', '<')) { + throw new Exception($this->getName() . ' requires Craft CMS 2.3.2615+ in order to run.'); } } - /* -------------------------------------------------------------- - * HOOKS - * ------------------------------------------------------------ */ + // ========================================================================= + // HOOKS + // ========================================================================= + + // FeedMe 1.4.0 + public function registerFeedMeMappingOptions() + { + return array( + 'SuperTable' => 'supertable/_plugins/feedMeOptions', + ); + } + + public function prepForFeedMeFieldType($field, &$data, $handle) + { + craft()->superTable->prepForFeedMeFieldType($field, $data, $handle); + } + + public function postForFeedMeFieldType(&$fieldData) + { + craft()->superTable->postForFeedMeFieldType($fieldData); + } + + // Export 0.5.8 + public function registerExportOperation(&$data, $handle) + { + craft()->superTable->registerExportOperation($data, $handle); + } } diff --git a/supertable/resources/css/SuperTableInput.css b/supertable/resources/css/SuperTableInput.css index af78997..8855c63 100644 --- a/supertable/resources/css/SuperTableInput.css +++ b/supertable/resources/css/SuperTableInput.css @@ -29,31 +29,18 @@ body.ltr table.editable.superTable tbody tr td:nth-child(2) { border-left: none; } -/* Strange issue for Categories and button alignment */ -.elements.structure li { - display: inline-block; - float: left; -} - -body.ltr .structure li:first-child { - padding-left: 0; -} - -.categoriesfield .btn { - margin-left: 10px; -} - /* Provide special formatting for some third-party field types. Just to make things clean */ .superTableContainer .field .linkit .linkit-type { - margin: 7px 0; + margin: 7px 0; } .superTableContainer .field .linkit .linkit-type-option, -.superTableContainer .field .linkit .linkit-text { - margin-bottom: 7px; +.superTableContainer .field .linkit .linkit-text, +.superTableContainer .field .linkit .linkit-target { + margin-bottom: 7px; } @@ -70,7 +57,7 @@ body.ltr .structure li:first-child { .superTableRow .rowHeader { font-weight: bold; - vertical-align: middle; + vertical-align: top; font-size: 11px; line-height: 1.2; color: rgba(0, 0, 0, 0.5); diff --git a/supertable/resources/icon.svg b/supertable/resources/icon.svg new file mode 100644 index 0000000..a7f9a0c --- /dev/null +++ b/supertable/resources/icon.svg @@ -0,0 +1,26 @@ + + + + +Untitled +Created with Sketch. + + + + + + + + + + + diff --git a/supertable/services/SuperTableService.php b/supertable/services/SuperTableService.php index 0276073..e738d35 100755 --- a/supertable/services/SuperTableService.php +++ b/supertable/services/SuperTableService.php @@ -632,6 +632,10 @@ public function getParentSuperTableField(FieldModel $superTableField) return $this->_parentSuperTableFields[$superTableField->id]; } + + + + // Private Methods // ========================================================================= @@ -799,4 +803,203 @@ private function _applyFieldTranslationSetting($owner, $field, $blocks) } } } + + + // Hook Methods + // ========================================================================= + + + + // Feed Me + // ========================================================================= + + public function prepForFeedMeFieldType($field, &$data, $handle) + { + if ($field->type == 'SuperTable') { + $content = array(); + + preg_match_all('/\w+/', $handle, $matches); + + if (isset($matches[0])) { + $fieldData = array(); + + $fieldHandle = $matches[0][0]; + $blocktypeHandle = $matches[0][1]; + $subFieldHandle = $matches[0][2]; + + // Store the fields for this Matrix - can't use the fields service due to context + $blockTypes = craft()->superTable->getBlockTypesByFieldId($field->id, 'id'); + $blockType = $blockTypes[$blocktypeHandle]; + + foreach ($blockType->getFields() as $f) { + if ($f->handle == $subFieldHandle) { + $subField = $f; + } + } + + $rows = array(); + + if (!empty($data)) { + if (!is_array($data)) { + $data = array($data); + } + + foreach ($data as $i => $singleFieldData) { + + // Check to see if this is an array of items, or just a single item + if (count($singleFieldData) != count($singleFieldData, 1)) { + $elementFieldData = array_values($singleFieldData)[0]; + + $subFieldData = craft()->feedMe_fields->prepForFieldType($elementFieldData, $subFieldHandle, $subField); + } else { + $subFieldData = craft()->feedMe_fields->prepForFieldType($singleFieldData, $subFieldHandle, $subField); + } + + $fieldData['new'.$blocktypeHandle.($i+1)] = array( + 'type' => $blocktypeHandle, + 'order' => $i, + 'enabled' => true, + 'fields' => $subFieldData, + ); + } + } + + $data[$fieldHandle] = $fieldData; + } + } + } + + public function postForFeedMeFieldType(&$fieldData) + { + // This is less intensive than craft()->fields->getFieldByHandle($fieldHandle); + foreach ($fieldData as $fieldHandle => $data) { + if (is_array($data)) { + + // Check for the order attr, otherwise not what we're after + if (isset(array_values($data)[0]['order'])) { + $orderedSuperTableData = array(); + $tempSuperTableData = array(); + + foreach ($data as $key => $subField) { + $tempSuperTableData[$subField['order']][$key] = $subField; + } + + $fieldData[$fieldHandle] = array(); + + foreach ($tempSuperTableData as $key => $subField) { + $fieldData[$fieldHandle] = array_merge($fieldData[$fieldHandle], $subField); + } + } + } + } + } + + + // Export + // ========================================================================= + + public function registerExportOperation(&$data, $handle) + { + $superTableField = craft()->fields->getFieldByHandle($handle); + + if ($superTableField) { + if ($superTableField->type == 'SuperTable') { + + $values = array(); + foreach ($data as $index => $block) { + foreach ($block->getFieldLayout()->getFields() as $fieldLayoutField) { + $field = $fieldLayoutField->getField(); + + $value = $block->getFieldValue($field->handle); + $value = $this->parseFieldData($field, $value); + + $values[] = $value; + } + } + + $data = $values; + } + } + } + + // Assists with Export functionality - prepares field content for export. Extracted from ExportService.php + protected function parseFieldData($field, $data) + { + if (!is_null($data)) { + if (!is_null($field)) { + switch ($field->type) { + case ExportModel::FieldTypeEntries: + case ExportModel::FieldTypeCategories: + case ExportModel::FieldTypeAssets: + case ExportModel::FieldTypeUsers: + $data = $data instanceof ElementCriteriaModel ? implode(', ', $data->find()) : $data; + + break; + + case ExportModel::FieldTypeLightswitch: + switch ($data) { + case '0': + $data = Craft::t('No'); + break; + + case '1': + $data = Craft::t('Yes'); + break; + } + + break; + + case ExportModel::FieldTypeTable: + $table = array(); + foreach ($data as $row) { + + $i = 1; + + foreach ($row as $column => $value) { + $column = isset($field->settings['columns'][$column]) ? $field->settings['columns'][$column] : (isset($field->settings['columns']['col'.$i]) ? $field->settings['columns']['col'.$i] : array('type' => 'dummy')); + + $i++; + + $table[] = $column['type'] == 'checkbox' ? ($value == 1 ? Craft::t('Yes') : Craft::t('No')) : $value; + } + } + + $data = $table; + + break; + + case ExportModel::FieldTypeRichText: + case ExportModel::FieldTypeDate: + case ExportModel::FieldTypeRadioButtons: + case ExportModel::FieldTypeDropdown: + $data = (string) $data; + + break; + + case ExportModel::FieldTypeCheckboxes: + case ExportModel::FieldTypeMultiSelect: + $multi = array(); + foreach ($data as $row) { + $multi[] = $row->value; + } + + $data = $multi; + + break; + } + } + } else { + $data = ''; + } + + if (is_array($data)) { + $data = StringHelper::arrayToString(ArrayHelper::filterEmptyStringsFromArray(ArrayHelper::flattenArray($data)), ', '); + } + + if (is_object($data)) { + $data = StringHelper::arrayToString(ArrayHelper::filterEmptyStringsFromArray(ArrayHelper::flattenArray(get_object_vars($data))), ', '); + } + + return $data; + } } diff --git a/supertable/templates/_plugins/feedMeOptions.html b/supertable/templates/_plugins/feedMeOptions.html new file mode 100644 index 0000000..cca7d7b --- /dev/null +++ b/supertable/templates/_plugins/feedMeOptions.html @@ -0,0 +1,14 @@ +{% for blocktype in craft.superTable.getSuperTableBlocks(field.id) %} + + {% endfor %} +{% endfor %} diff --git a/supertable/variables/SuperTableVariable.php b/supertable/variables/SuperTableVariable.php index 9cf0ebd..b413771 100644 --- a/supertable/variables/SuperTableVariable.php +++ b/supertable/variables/SuperTableVariable.php @@ -137,6 +137,11 @@ public function getMatrixInputHtml($fieldType, $name, $value) return $html; } + public function getSuperTableBlocks($fieldId) + { + return craft()->superTable->getBlockTypesByFieldId($fieldId); + } + private function _getBlockTypeInfoForInput($fieldType, $name) { $blockTypes = array();