From 3e1f0f5680f655457f354af650df76570d4c66ae Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Mon, 2 Nov 2015 14:26:54 +0100 Subject: [PATCH 01/19] Moved fields export logic to factory classes --- models/Schematic_FieldFactoryModel.php | 36 +++++ models/Schematic_FieldModel.php | 87 ++++++++++++ models/Schematic_MatrixFieldModel.php | 60 ++++++++ services/Schematic_FieldsService.php | 181 +++++++------------------ 4 files changed, 235 insertions(+), 129 deletions(-) create mode 100644 models/Schematic_FieldFactoryModel.php create mode 100644 models/Schematic_FieldModel.php create mode 100644 models/Schematic_MatrixFieldModel.php diff --git a/models/Schematic_FieldFactoryModel.php b/models/Schematic_FieldFactoryModel.php new file mode 100644 index 00000000..a48cde20 --- /dev/null +++ b/models/Schematic_FieldFactoryModel.php @@ -0,0 +1,36 @@ +getSchematicFieldModel($field->type); + return $schematicFieldModel->getDefinition($field, $includeContext); + } + + /** + * @param $fieldType + * @return Schematic_FieldModel + */ + private function getSchematicFieldModel($fieldType) + { + $className = 'Craft\Schematic_' . ucfirst($fieldType) . 'FieldModel'; + + if (class_exists($className)) { + return new $className; + } + return new Schematic_FieldModel(); + } +} diff --git a/models/Schematic_FieldModel.php b/models/Schematic_FieldModel.php new file mode 100644 index 00000000..08549191 --- /dev/null +++ b/models/Schematic_FieldModel.php @@ -0,0 +1,87 @@ +schematic_fields->getFieldFactory(); + } + + /** + * @param FieldModel $field + * @param $includeContext + * @return array + */ + public function getDefinition(FieldModel $field, $includeContext) + { + $definition = array( + 'name' => $field->name, + 'required' => $field->required, + 'instructions' => $field->instructions, + 'translatable' => $field->translatable, + 'type' => $field->type, + 'settings' => $field->settings, + ); + + if ($includeContext) { + $definition['context'] = $field->context; + } + + if (isset($definition['settings']['sources'])) { + $definition['settings']['sources'] = $this->getSourceHandles($definition['settings']['sources']); + } + + return $definition; + } + + /** + * Get source handles. + * + * @param string|array $sourcesWithIds + * + * @return string|array + */ + private function getSourceHandles($sourcesWithIds) + { + if (!is_array($sourcesWithIds)) { + return $sourcesWithIds; + } + $sourcesWithHandles = array(); + foreach ($sourcesWithIds as $sourceWithId) { + $sourcesWithHandles[] = $this->getSourceHandle($sourceWithId); + } + + return $sourcesWithHandles; + } + + /** + * @param string $source with id + * @return string source with handle + */ + private function getSourceHandle($source) + { + if (strpos($source, ':') > -1) { + /** @var BaseElementModel $sourceObject */ + $sourceObject = null; + list($sourceType, $sourceId) = explode(':', $source); + + switch ($sourceType) { + case 'section': + $sourceObject = craft()->sections->getSectionById($sourceId); + break; + case 'group': + $sourceObject = craft()->userGroups->getGroupById($sourceId); + break; + } + if ($sourceObject) { + $source = $sourceType . ':' . $sourceObject->handle; + } + } + return $source; + } +} diff --git a/models/Schematic_MatrixFieldModel.php b/models/Schematic_MatrixFieldModel.php new file mode 100644 index 00000000..d3f50ee7 --- /dev/null +++ b/models/Schematic_MatrixFieldModel.php @@ -0,0 +1,60 @@ +matrix; + } + + + /** + * @param FieldModel $field + * @param $includeContext + * @return array + */ + public function getDefinition(FieldModel $field, $includeContext) + { + $definition = parent::getDefinition($field, $includeContext); + $definition['blockTypes'] = $this->getBlockTypeDefinitions($field); + + return $definition; + } + + /** + * Get block type definitions. + * + * @param FieldModel $field + * + * @return array + */ + private function getBlockTypeDefinitions(FieldModel $field) + { + $fieldFactory = $this->getFieldFactory(); + $blockTypeDefinitions = array(); + + $blockTypes = $this->getMatrixService()->getBlockTypesByFieldId($field->id); + foreach ($blockTypes as $blockType) { + $blockTypeFieldDefinitions = array(); + + foreach ($blockType->getFields() as $blockTypeField) { + $blockTypeFieldDefinitions[$blockTypeField->handle] = $fieldFactory->getDefinition($blockTypeField, false); + } + + $blockTypeDefinitions[$blockType->handle] = array( + 'name' => $blockType->name, + 'fields' => $blockTypeFieldDefinitions, + ); + } + + return $blockTypeDefinitions; + } +} diff --git a/services/Schematic_FieldsService.php b/services/Schematic_FieldsService.php index 16cee184..d63f4659 100644 --- a/services/Schematic_FieldsService.php +++ b/services/Schematic_FieldsService.php @@ -25,6 +25,11 @@ class Schematic_FieldsService extends Schematic_AbstractService */ private $groups = array(); + /** + * @var Schematic_FieldFactoryModel + */ + private $fieldFactory; + /** * Constructor. */ @@ -36,6 +41,18 @@ public function __construct() $this->fields = $this->getFieldsService()->getAllFields('handle'); } + /** + * @return Schematic_FieldFactoryModel + */ + public function getFieldFactory() + { + return isset($this->fieldFactory) ? $this->fieldFactory : new Schematic_FieldFactoryModel(); + } + + //============================================================================================================== + //=============================================== SERVICES =================================================== + //============================================================================================================== + /** * Returns fields service. * @@ -56,15 +73,9 @@ private function getContentService() return craft()->content; } - /** - * Returns matrix service. - * - * @return MatrixService - */ - private function getMatrixService() - { - return craft()->matrix; - } + //============================================================================================================== + //================================================ EXPORT ==================================================== + //============================================================================================================== /** * Export fields. @@ -94,107 +105,61 @@ public function export(array $groups = array()) * Get field definition. * * @param FieldModel $field - * @param bool $includeContext * * @return array */ - private function getFieldDefinition(FieldModel $field, $includeContext = true) + private function getFieldDefinition(FieldModel $field) { - $definition = array( - 'name' => $field->name, - 'required' => $field->required, - 'instructions' => $field->instructions, - 'translatable' => $field->translatable, - 'type' => $field->type, - 'settings' => $field->settings, - ); - - if ($includeContext) { - $definition['context'] = $field->context; - } - if (isset($definition['settings']['sources'])) { - $definition['settings']['sources'] = $this->getSourceHandles($definition['settings']['sources']); - } - - if ($field->type == 'Matrix') { - $definition['blockTypes'] = $this->getBlockTypeDefinitions($field); - } + $fieldFactory = $this->getFieldFactory(); + $definition = $fieldFactory->getDefinition($field); return $definition; } + //============================================================================================================== + //================================================ IMPORT ==================================================== + //============================================================================================================== + /** - * Get source handles. + * Attempt to import fields. * - * @param string|array $sourcesWithIds + * @param array $groupDefinitions + * @param bool $force if set to true items not in the import will be deleted * - * @return string|array + * @return Schematic_ResultModel */ - private function getSourceHandles($sourcesWithIds) + public function import(array $groupDefinitions, $force = false) { - if (!is_array($sourcesWithIds)) { - return $sourcesWithIds; - } - $sourcesWithHandles = array(); - foreach ($sourcesWithIds as $sourceWithId) { - $sourcesWithHandles[] = $this->getSourceHandle($sourceWithId); - } + if (!empty($groupDefinitions)) { + $contentService = $this->getContentService(); - return $sourcesWithHandles; - } + $contentService->fieldContext = 'global'; + $contentService->contentTable = 'content'; - /** - * @param string $source with id - * @return string source with handle - */ - private function getSourceHandle($source) - { - if (strpos($source, ':') > -1) { - /** @var BaseElementModel $sourceObject */ - $sourceObject = null; - list($sourceType, $sourceId) = explode(':', $source); + foreach ($groupDefinitions as $name => $fieldDefinitions) { + try { + $this->beginTransaction(); - switch ($sourceType) { - case 'section': - $sourceObject = craft()->sections->getSectionById($sourceId); - break; - case 'group': - $sourceObject = craft()->userGroups->getGroupById($sourceId); - break; - } - if ($sourceObject) { - $source = $sourceType . ':' . $sourceObject->handle; - } - } - return $source; - } + $group = $this->createFieldGroupModel($name); - /** - * Get block type definitions. - * - * @param FieldModel $field - * - * @return array - */ - private function getBlockTypeDefinitions(FieldModel $field) - { - $blockTypeDefinitions = array(); + $this->importFields($fieldDefinitions, $group); - $blockTypes = $this->getMatrixService()->getBlockTypesByFieldId($field->id); - foreach ($blockTypes as $blockType) { - $blockTypeFieldDefinitions = array(); + $this->commitTransaction(); + } catch (\Exception $e) { + $this->rollbackTransaction(); - foreach ($blockType->getFields() as $blockTypeField) { - $blockTypeFieldDefinitions[$blockTypeField->handle] = $this->getFieldDefinition($blockTypeField, false); + $this->addError($e->getMessage()); + } + + $this->unsetData($name, $fieldDefinitions); } - $blockTypeDefinitions[$blockType->handle] = array( - 'name' => $blockType->name, - 'fields' => $blockTypeFieldDefinitions, - ); + if ($force) { // Remove not imported data + $this->deleteFieldsAndGroups(); + } } - return $blockTypeDefinitions; + return $this->getResultModel(); } /** @@ -342,48 +307,6 @@ private function unsetData($name, array $definitions) } } - /** - * Attempt to import fields. - * - * @param array $groupDefinitions - * @param bool $force if set to true items not in the import will be deleted - * - * @return Schematic_ResultModel - */ - public function import(array $groupDefinitions, $force = false) - { - if (!empty($groupDefinitions)) { - $contentService = $this->getContentService(); - - $contentService->fieldContext = 'global'; - $contentService->contentTable = 'content'; - - foreach ($groupDefinitions as $name => $fieldDefinitions) { - try { - $this->beginTransaction(); - - $group = $this->createFieldGroupModel($name); - - $this->importFields($fieldDefinitions, $group); - - $this->commitTransaction(); - } catch (\Exception $e) { - $this->rollbackTransaction(); - - $this->addError($e->getMessage()); - } - - $this->unsetData($name, $fieldDefinitions); - } - - if ($force) { // Remove not imported data - $this->deleteFieldsAndGroups(); - } - } - - return $this->getResultModel(); - } - /** * Populate blocktype. * From 0199722bddcbc2f04da8118c166bee84fb9c6b45 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Mon, 2 Nov 2015 14:41:04 +0100 Subject: [PATCH 02/19] Implemented export for supertable --- models/Schematic_MatrixFieldModel.php | 5 ++++- models/Schematic_SuperTablefieldModel.php | 0 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 models/Schematic_SuperTablefieldModel.php diff --git a/models/Schematic_MatrixFieldModel.php b/models/Schematic_MatrixFieldModel.php index d3f50ee7..ebb4bac7 100644 --- a/models/Schematic_MatrixFieldModel.php +++ b/models/Schematic_MatrixFieldModel.php @@ -2,6 +2,9 @@ namespace Craft; +/** + * Class Schematic_MatrixFieldModel + */ class Schematic_MatrixFieldModel extends Schematic_FieldModel { @@ -36,7 +39,7 @@ public function getDefinition(FieldModel $field, $includeContext) * * @return array */ - private function getBlockTypeDefinitions(FieldModel $field) + protected function getBlockTypeDefinitions(FieldModel $field) { $fieldFactory = $this->getFieldFactory(); $blockTypeDefinitions = array(); diff --git a/models/Schematic_SuperTablefieldModel.php b/models/Schematic_SuperTablefieldModel.php new file mode 100644 index 00000000..e69de29b From 2c5a41d53f509d151f735a80599121ceba99def5 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Mon, 2 Nov 2015 16:13:41 +0100 Subject: [PATCH 03/19] Moved much of the field import logic to the fieldfactory and related schematic field models --- models/Schematic_FieldFactoryModel.php | 15 +- models/Schematic_FieldModel.php | 88 +++++++++++ models/Schematic_MatrixFieldModel.php | 85 ++++++++++ models/Schematic_PositionSelectModel.php | 0 models/Schematic_SuperTablefieldModel.php | 93 +++++++++++ services/Schematic_FieldsService.php | 180 ++-------------------- 6 files changed, 289 insertions(+), 172 deletions(-) create mode 100644 models/Schematic_PositionSelectModel.php diff --git a/models/Schematic_FieldFactoryModel.php b/models/Schematic_FieldFactoryModel.php index a48cde20..85f3fa33 100644 --- a/models/Schematic_FieldFactoryModel.php +++ b/models/Schematic_FieldFactoryModel.php @@ -4,9 +4,20 @@ class Schematic_FieldFactoryModel { - public function buildField(array $fieldDefinition) + + /** + * @param array $fieldDefinition + * @param FieldModel $field + * @param string $fieldHandle + * @param FieldGroupModel|null $group + * @return FieldModel + */ + public function populate(array $fieldDefinition, FieldModel $field, $fieldHandle, FieldGroupModel $group = null) { + $schematicFieldModel = $this->getSchematicFieldModel($fieldDefinition['type']); + $schematicFieldModel->populate($fieldDefinition, $field, $fieldHandle, $group); + return $field; } /** @@ -17,6 +28,7 @@ public function buildField(array $fieldDefinition) public function getDefinition(FieldModel $field, $includeContext = true) { $schematicFieldModel = $this->getSchematicFieldModel($field->type); + return $schematicFieldModel->getDefinition($field, $includeContext); } @@ -31,6 +43,7 @@ private function getSchematicFieldModel($fieldType) if (class_exists($className)) { return new $className; } + return new Schematic_FieldModel(); } } diff --git a/models/Schematic_FieldModel.php b/models/Schematic_FieldModel.php index 08549191..5dbe8962 100644 --- a/models/Schematic_FieldModel.php +++ b/models/Schematic_FieldModel.php @@ -2,6 +2,9 @@ namespace Craft; +/** + * Class Schematic_FieldModel + */ class Schematic_FieldModel { /** @@ -12,6 +15,10 @@ public function getFieldFactory() return craft()->schematic_fields->getFieldFactory(); } + //============================================================================================================== + //================================================ EXPORT ==================================================== + //============================================================================================================== + /** * @param FieldModel $field * @param $includeContext @@ -84,4 +91,85 @@ private function getSourceHandle($source) } return $source; } + + //============================================================================================================== + //================================================ IMPORT ==================================================== + //============================================================================================================== + + /** + * @param array $fieldDefinition + * @param FieldModel $field + * @param string $fieldHandle + * @param FieldGroupModel|null $group + */ + public function populate(array $fieldDefinition, FieldModel $field, $fieldHandle, FieldGroupModel $group = null) + { + $field->name = $fieldDefinition['name']; + $field->handle = $fieldHandle; + $field->required = $fieldDefinition['required']; + $field->translatable = $fieldDefinition['translatable']; + $field->instructions = $fieldDefinition['instructions']; + $field->type = $fieldDefinition['type']; + $field->settings = $fieldDefinition['settings']; + + if ($group) { + $field->groupId = $group->id; + } + + if (isset($definition['settings']['sources'])) { + $settings = $fieldDefinition['settings']; + $settings['sources'] = $this->getSourceIds($settings['sources']); + $field->settings = $settings; + } + } + + /** + * Get source id's. + * + * @param string|array $sourcesWithHandle + * + * @return string|array + */ + private function getSourceIds($sourcesWithHandle) + { + if (!is_array($sourcesWithHandle)) { + return $sourcesWithHandle; + } + $sourcesWithIds = array(); + foreach ($sourcesWithHandle as $sourceWithHandle) { + $sourcesWithIds[] = $this->getSourceId($sourceWithHandle); + } + return $sourcesWithIds; + } + + /** + * @param $source + * @return string + */ + private function getSourceId($source) + { + /** @var BaseElementModel $sourceObject */ + $sourceObject = null; + if (strpos($source, ':') > -1) { + list($sourceType, $sourceHandle) = explode(':', $source); + + switch ($sourceType) { + case 'section': + $sourceObject = craft()->sections->getSectionByHandle($sourceHandle); + break; + case 'group': + $sourceObject = craft()->userGroups->getGroupByHandle($sourceHandle); + break; + } + } elseif ($source !== 'singles') { + //Backwards compatibility + $sourceType = 'section'; + $sourceObject = craft()->sections->getSectionByHandle($source); + } + if ($sourceObject && isset($sourceType)) { + $source = $sourceType . ':' . $sourceObject->id; + } + + return $source; + } } diff --git a/models/Schematic_MatrixFieldModel.php b/models/Schematic_MatrixFieldModel.php index ebb4bac7..55fd475e 100644 --- a/models/Schematic_MatrixFieldModel.php +++ b/models/Schematic_MatrixFieldModel.php @@ -18,6 +18,9 @@ private function getMatrixService() return craft()->matrix; } + //============================================================================================================== + //================================================ EXPORT ==================================================== + //============================================================================================================== /** * @param FieldModel $field @@ -60,4 +63,86 @@ protected function getBlockTypeDefinitions(FieldModel $field) return $blockTypeDefinitions; } + + //============================================================================================================== + //================================================ IMPORT ==================================================== + //============================================================================================================== + + /** + * @param array $fieldDefinition + * @param FieldModel $field + * @param string $fieldHandle + * @param FieldGroupModel|null $group + */ + public function populate(array $fieldDefinition, FieldModel $field, $fieldHandle, FieldGroupModel $group = null) + { + parent::populate($fieldDefinition, $field, $fieldHandle, $group); + + /** @var MatrixSettingsModel $settingsModel */ + $settingsModel = $field->getFieldType()->getSettings(); + $settingsModel->setAttributes($fieldDefinition['settings']); + $settingsModel->setBlockTypes($this->getBlockTypes($fieldDefinition, $field)); + $field->settings = $settingsModel; + } + + /** + * Get blocktypes. + * + * @param array $fieldDefinition + * @param FieldModel $field + * + * @return mixed + */ + protected function getBlockTypes(array $fieldDefinition, FieldModel $field) + { + $blockTypes = craft()->matrix->getBlockTypesByFieldId($field->id, 'handle'); + + foreach ($fieldDefinition['blockTypes'] as $blockTypeHandle => $blockTypeDef) { + $blockType = array_key_exists($blockTypeHandle, $blockTypes) + ? $blockTypes[$blockTypeHandle] + : new MatrixBlockTypeModel(); + + $this->populateBlockType($field, $blockType, $blockTypeDef, $blockTypeHandle); + + $blockTypes[$blockTypeHandle] = $blockType; + } + + return $blockTypes; + } + + /** + * Populate blocktype. + * + * @param FieldModel $field + * @param MatrixBlockTypeModel $blockType + * @param array $blockTypeDef + * @param string $blockTypeHandle + */ + private function populateBlockType(FieldModel $field, MatrixBlockTypeModel $blockType, array $blockTypeDef, $blockTypeHandle) + { + $fieldFactory = $this->getFieldFactory(); + + $blockType->fieldId = $field->id; + $blockType->name = $blockTypeDef['name']; + $blockType->handle = $blockTypeHandle; + + $blockTypeFields = array(); + foreach ($blockType->getFields() as $blockTypeField) { + $blockTypeFields[$blockTypeField->handle] = $blockTypeField; + } + + $newBlockTypeFields = array(); + + foreach ($blockTypeDef['fields'] as $blockTypeFieldHandle => $blockTypeFieldDef) { + $blockTypeField = array_key_exists($blockTypeFieldHandle, $blockTypeFields) + ? $blockTypeFields[$blockTypeFieldHandle] + : new FieldModel(); + + $fieldFactory->populate($blockTypeFieldDef, $blockTypeField, $blockTypeFieldHandle); + + $newBlockTypeFields[] = $blockTypeField; + } + + $blockType->setFields($newBlockTypeFields); + } } diff --git a/models/Schematic_PositionSelectModel.php b/models/Schematic_PositionSelectModel.php new file mode 100644 index 00000000..e69de29b diff --git a/models/Schematic_SuperTablefieldModel.php b/models/Schematic_SuperTablefieldModel.php index e69de29b..0d612513 100644 --- a/models/Schematic_SuperTablefieldModel.php +++ b/models/Schematic_SuperTablefieldModel.php @@ -0,0 +1,93 @@ +superTable; + } + + /** + * Get block type definitions. + * + * @param FieldModel $field + * + * @return array + */ + protected function getBlockTypeDefinitions(FieldModel $field) + { + $fieldFactory = $this->getFieldFactory(); + $blockTypeDefinitions = array(); + + /** @var SuperTable_BlockTypeModel[] $blockTypes */ + $blockTypes = $this->getSuperTableService()->getBlockTypesByFieldId($field->id); + foreach ($blockTypes as $blockType) { + $blockTypeFieldDefinitions = array(); + + foreach ($blockType->getFields() as $blockTypeField) { + $blockTypeFieldDefinitions[$blockTypeField->handle] = $fieldFactory->getDefinition($blockTypeField, false); + } + + $blockTypeDefinitions[] = array( + 'fields' => $blockTypeFieldDefinitions, + ); + } + + return $blockTypeDefinitions; + } + + /** + * @param array $fieldDefinition + * @param FieldModel $field + * @return SuperTable_BlockTypeModel[] + */ + protected function getBlockTypes(array $fieldDefinition, FieldModel $field) + { + $blockTypes = array(); + foreach ($fieldDefinition['blockTypes'] as $blockTypeId => $blockTypeDef) { + $blockType = new SuperTable_BlockTypeModel(); + $this->populateBlockType($field, $blockType, $blockTypeDef); + $blockTypes[] = $blockType; + } + return $blockTypes; + } + + /** + * @param FieldModel $field + * @param SuperTable_BlockTypeModel $blockType + * @param array $blockTypeDef + */ + private function populateBlockType(FieldModel $field, SuperTable_BlockTypeModel $blockType, array $blockTypeDef) + { + $fieldFactory = $this->getFieldFactory(); + + $blockType->fieldId = $field->id; + + $blockTypeFields = array(); + foreach ($blockType->getFields() as $blockTypeField) { + $blockTypeFields[$blockTypeField->handle] = $blockTypeField; + } + + $newBlockTypeFields = array(); + + foreach ($blockTypeDef['fields'] as $blockTypeFieldHandle => $blockTypeFieldDef) { + $blockTypeField = array_key_exists($blockTypeFieldHandle, $blockTypeFields) + ? $blockTypeFields[$blockTypeFieldHandle] + : new FieldModel(); + + $fieldFactory->populate($blockTypeFieldDef, $blockTypeField, $blockTypeFieldHandle); + + $newBlockTypeFields[] = $blockTypeField; + } + + $blockType->setFields($newBlockTypeFields); + } +} diff --git a/services/Schematic_FieldsService.php b/services/Schematic_FieldsService.php index d63f4659..dcc0648f 100644 --- a/services/Schematic_FieldsService.php +++ b/services/Schematic_FieldsService.php @@ -30,16 +30,6 @@ class Schematic_FieldsService extends Schematic_AbstractService */ private $fieldFactory; - /** - * Constructor. - */ - public function __construct() - { - parent::__construct(); - - $this->groups = $this->getFieldsService()->getAllGroups('name'); - $this->fields = $this->getFieldsService()->getAllFields('handle'); - } /** * @return Schematic_FieldFactoryModel @@ -131,6 +121,9 @@ private function getFieldDefinition(FieldModel $field) public function import(array $groupDefinitions, $force = false) { if (!empty($groupDefinitions)) { + $this->groups = $this->getFieldsService()->getAllGroups('name'); + $this->fields = $this->getFieldsService()->getAllFields('handle'); + $contentService = $this->getContentService(); $contentService->fieldContext = 'global'; @@ -282,11 +275,11 @@ private function validateFieldModel(FieldModel $field) */ private function importFields(array $fieldDefinitions, FieldGroupModel $group) { + $fieldFactory = $this->getFieldFactory(); + foreach ($fieldDefinitions as $fieldHandle => $fieldDef) { $field = $this->getFieldModel($fieldHandle); - - $this->populateField($fieldDef, $field, $fieldHandle, $group); - + $fieldFactory->populate($fieldDef, $field, $fieldHandle, $group); $this->saveFieldModel($field); } } @@ -307,164 +300,9 @@ private function unsetData($name, array $definitions) } } - /** - * Populate blocktype. - * - * @param FieldModel $field - * @param MatrixBlockTypeModel $blockType - * @param array $blockTypeDef - * @param string $blockTypeHandle - */ - private function populateBlockType(FieldModel $field, MatrixBlockTypeModel $blockType, array $blockTypeDef, $blockTypeHandle) - { - $blockType->fieldId = $field->id; - $blockType->name = $blockTypeDef['name']; - $blockType->handle = $blockTypeHandle; - - $blockTypeFields = array(); - foreach ($blockType->getFields() as $blockTypeField) { - $blockTypeFields[$blockTypeField->handle] = $blockTypeField; - } - - $newBlockTypeFields = array(); - - foreach ($blockTypeDef['fields'] as $blockTypeFieldHandle => $blockTypeFieldDef) { - $blockTypeField = array_key_exists($blockTypeFieldHandle, $blockTypeFields) - ? $blockTypeFields[$blockTypeFieldHandle] - : new FieldModel(); - - $this->populateField($blockTypeFieldDef, $blockTypeField, $blockTypeFieldHandle); - - $newBlockTypeFields[] = $blockTypeField; - } - - $blockType->setFields($newBlockTypeFields); - } - - /** - * Populate field. - * - * @param array $fieldDefinition - * @param FieldModel $field - * @param string $fieldHandle - * @param FieldGroupModel $group - */ - private function populateField( - array $fieldDefinition, - FieldModel $field, - $fieldHandle, - FieldGroupModel $group = null - ) - { - $field->name = $fieldDefinition['name']; - $field->handle = $fieldHandle; - $field->required = $fieldDefinition['required']; - $field->translatable = $fieldDefinition['translatable']; - $field->instructions = $fieldDefinition['instructions']; - $field->type = $fieldDefinition['type']; - $field->settings = $fieldDefinition['settings']; - - if ($group) { - $field->groupId = $group->id; - } - - if ($field->type == 'Entries') { - $settings = $fieldDefinition['settings']; - $settings['sources'] = $this->getSourceIds($settings['sources']); - $field->settings = $settings; - } - - if ($field->type == 'PositionSelect') { - $options = array(); - $settings = $fieldDefinition['settings']; - foreach ($settings['options'] as $option) { - $options[$option] = $option; - } - $settings['options'] = $options; - $field->settings = $settings; - } - - if ($field->type == 'Matrix') { - $field->settings = $field->getFieldType()->getSettings(); - $field->settings->setAttributes($fieldDefinition['settings']); - $field->settings->setBlockTypes($this->getBlockTypes($fieldDefinition, $field)); - } - } - - /** - * Get source id's. - * - * @param string|array $sourcesWithHandle - * - * @return string|array - */ - private function getSourceIds($sourcesWithHandle) - { - if (!is_array($sourcesWithHandle)) { - return $sourcesWithHandle; - } - $sourcesWithIds = array(); - foreach ($sourcesWithHandle as $sourceWithHandle) { - $sourcesWithIds[] = $this->getSourceId($sourceWithHandle); - } - return $sourcesWithIds; - } - - /** - * @param $source - * @return string - */ - private function getSourceId($source) - { - /** @var BaseElementModel $sourceObject */ - $sourceObject = null; - if (strpos($source, ':') > -1) { - list($sourceType, $sourceHandle) = explode(':', $source); - - switch ($sourceType) { - case 'section': - $sourceObject = craft()->sections->getSectionByHandle($sourceHandle); - break; - case 'group': - $sourceObject = craft()->userGroups->getGroupByHandle($sourceHandle); - break; - } - } elseif ($source !== 'singles') { - //Backwards compatibility - $sourceType = 'section'; - $sourceObject = craft()->sections->getSectionByHandle($source); - } - if ($sourceObject && isset($sourceType)) { - $source = $sourceType . ':' . $sourceObject->id; - } - - return $source; - } - - /** - * Get blocktypes. - * - * @param array $fieldDefinition - * @param FieldModel $field - * - * @return mixed - */ - private function getBlockTypes(array $fieldDefinition, FieldModel $field) - { - $blockTypes = craft()->matrix->getBlockTypesByFieldId($field->id, 'handle'); - - foreach ($fieldDefinition['blockTypes'] as $blockTypeHandle => $blockTypeDef) { - $blockType = array_key_exists($blockTypeHandle, $blockTypes) - ? $blockTypes[$blockTypeHandle] - : new MatrixBlockTypeModel(); - - $this->populateBlockType($field, $blockType, $blockTypeDef, $blockTypeHandle); - - $blockTypes[$blockTypeHandle] = $blockType; - } - - return $blockTypes; - } + //============================================================================================================== + //============================================= FIELD LAYOUT ================================================= + //============================================================================================================== /** * Get field layout definition. From 0751919ec83e19b60cf0c2d24cce09861a4a9c69 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Mon, 2 Nov 2015 16:36:28 +0100 Subject: [PATCH 04/19] Specific populate for PositionSelect field --- models/Schematic_PositionSelectModel.php | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/models/Schematic_PositionSelectModel.php b/models/Schematic_PositionSelectModel.php index e69de29b..71b006be 100644 --- a/models/Schematic_PositionSelectModel.php +++ b/models/Schematic_PositionSelectModel.php @@ -0,0 +1,28 @@ +settings = $settings; + } +} From e240c5fad176b3728350245489b331b4789de602 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Mon, 2 Nov 2015 16:36:51 +0100 Subject: [PATCH 05/19] Refactor of mapping of sources in Schematic_FieldModel --- models/Schematic_FieldModel.php | 120 +++++++++++++------------------- 1 file changed, 48 insertions(+), 72 deletions(-) diff --git a/models/Schematic_FieldModel.php b/models/Schematic_FieldModel.php index 5dbe8962..81724c0a 100644 --- a/models/Schematic_FieldModel.php +++ b/models/Schematic_FieldModel.php @@ -15,9 +15,21 @@ public function getFieldFactory() return craft()->schematic_fields->getFieldFactory(); } - //============================================================================================================== - //================================================ EXPORT ==================================================== - //============================================================================================================== + /** + * @return SectionsService + */ + private function getSectionsService() + { + return craft()->sections; + } + + /** + * @return UserGroupsService + */ + private function getUserGroupsService() + { + return craft()->userGroups; + } /** * @param FieldModel $field @@ -40,62 +52,12 @@ public function getDefinition(FieldModel $field, $includeContext) } if (isset($definition['settings']['sources'])) { - $definition['settings']['sources'] = $this->getSourceHandles($definition['settings']['sources']); + $definition['settings']['sources'] = $this->getMappedSources($definition['settings']['sources'], 'id', 'handle'); } return $definition; } - /** - * Get source handles. - * - * @param string|array $sourcesWithIds - * - * @return string|array - */ - private function getSourceHandles($sourcesWithIds) - { - if (!is_array($sourcesWithIds)) { - return $sourcesWithIds; - } - $sourcesWithHandles = array(); - foreach ($sourcesWithIds as $sourceWithId) { - $sourcesWithHandles[] = $this->getSourceHandle($sourceWithId); - } - - return $sourcesWithHandles; - } - - /** - * @param string $source with id - * @return string source with handle - */ - private function getSourceHandle($source) - { - if (strpos($source, ':') > -1) { - /** @var BaseElementModel $sourceObject */ - $sourceObject = null; - list($sourceType, $sourceId) = explode(':', $source); - - switch ($sourceType) { - case 'section': - $sourceObject = craft()->sections->getSectionById($sourceId); - break; - case 'group': - $sourceObject = craft()->userGroups->getGroupById($sourceId); - break; - } - if ($sourceObject) { - $source = $sourceType . ':' . $sourceObject->handle; - } - } - return $source; - } - - //============================================================================================================== - //================================================ IMPORT ==================================================== - //============================================================================================================== - /** * @param array $fieldDefinition * @param FieldModel $field @@ -118,56 +80,70 @@ public function populate(array $fieldDefinition, FieldModel $field, $fieldHandle if (isset($definition['settings']['sources'])) { $settings = $fieldDefinition['settings']; - $settings['sources'] = $this->getSourceIds($settings['sources']); + $settings['sources'] = $this->getMappedSources($settings['sources'], 'handle', 'id'); $field->settings = $settings; } } /** - * Get source id's. + * Get sources based on the indexFrom attribute and return them with the indexTo attribute * - * @param string|array $sourcesWithHandle + * @param string|array $sources * * @return string|array */ - private function getSourceIds($sourcesWithHandle) + private function getMappedSources($sources, $indexFrom, $indexTo) { - if (!is_array($sourcesWithHandle)) { - return $sourcesWithHandle; + if (!is_array($sources)) { + return $sources; } - $sourcesWithIds = array(); - foreach ($sourcesWithHandle as $sourceWithHandle) { - $sourcesWithIds[] = $this->getSourceId($sourceWithHandle); + + $mappedSources = array(); + foreach ($sources as $source) { + $mappedSources[] = $this->getSource($source, $indexFrom, $indexTo); } - return $sourcesWithIds; + + return $mappedSources; } /** - * @param $source + * Gets a source by the attribute indexFrom, and returns it with attribute $indexTo + * @param string $source + * @param string $indexFrom + * @param string $indexTo * @return string */ - private function getSourceId($source) + private function getSource($source, $indexFrom, $indexTo) { /** @var BaseElementModel $sourceObject */ $sourceObject = null; - if (strpos($source, ':') > -1) { - list($sourceType, $sourceHandle) = explode(':', $source); + if (strpos($source, ':') > -1) { + list($sourceType, $sourceFrom) = explode(':', $source); switch ($sourceType) { case 'section': - $sourceObject = craft()->sections->getSectionByHandle($sourceHandle); + $service = $this->getSectionsService(); + $method = 'getSectionBy'; break; case 'group': - $sourceObject = craft()->userGroups->getGroupByHandle($sourceHandle); + $service = $this->getUserGroupsService(); + $method = 'getGroupBy'; break; } } elseif ($source !== 'singles') { //Backwards compatibility $sourceType = 'section'; - $sourceObject = craft()->sections->getSectionByHandle($source); + $service = $this->getSectionsService(); + $method = 'getSectionBy'; } + + if(isset($service) && isset($method)){ + $method = $method . $indexFrom; + $sourceObject = $service->$method($source->$indexFrom); + } + if ($sourceObject && isset($sourceType)) { - $source = $sourceType . ':' . $sourceObject->id; + $source = $sourceType . ':' . $sourceObject->$indexTo; } return $source; From 2a4d2fd3bb7b0d884b7b1e0ce92dafc9d0266bc2 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Mon, 2 Nov 2015 16:40:44 +0100 Subject: [PATCH 06/19] Filename fix for SuperTableFieldModel --- ...uperTablefieldModel.php => Schematic_SuperTableFieldModel.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename models/{Schematic_SuperTablefieldModel.php => Schematic_SuperTableFieldModel.php} (100%) diff --git a/models/Schematic_SuperTablefieldModel.php b/models/Schematic_SuperTableFieldModel.php similarity index 100% rename from models/Schematic_SuperTablefieldModel.php rename to models/Schematic_SuperTableFieldModel.php From b2c8bef6a89cd1efc55a02d7cffd8c2a70afbe80 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Mon, 2 Nov 2015 16:41:53 +0100 Subject: [PATCH 07/19] Rename of positionselect field model for consistency --- ...tionSelectModel.php => Schematic_PositionSelectFieldModel.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename models/{Schematic_PositionSelectModel.php => Schematic_PositionSelectFieldModel.php} (100%) diff --git a/models/Schematic_PositionSelectModel.php b/models/Schematic_PositionSelectFieldModel.php similarity index 100% rename from models/Schematic_PositionSelectModel.php rename to models/Schematic_PositionSelectFieldModel.php From 238484feb6b1ae29407174f9bd2adbbe2b0ecaf4 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Mon, 2 Nov 2015 17:04:28 +0100 Subject: [PATCH 08/19] Couple of fixes for field sources --- models/Schematic_FieldModel.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/models/Schematic_FieldModel.php b/models/Schematic_FieldModel.php index 81724c0a..290dd10d 100644 --- a/models/Schematic_FieldModel.php +++ b/models/Schematic_FieldModel.php @@ -90,7 +90,9 @@ public function populate(array $fieldDefinition, FieldModel $field, $fieldHandle * * @param string|array $sources * - * @return string|array + * @param string $indexFrom + * @param string $indexTo + * @return array|string */ private function getMappedSources($sources, $indexFrom, $indexTo) { @@ -133,13 +135,14 @@ private function getSource($source, $indexFrom, $indexTo) } elseif ($source !== 'singles') { //Backwards compatibility $sourceType = 'section'; + $sourceFrom = $source; $service = $this->getSectionsService(); $method = 'getSectionBy'; } - if(isset($service) && isset($method)){ + if (isset($service) && isset($method) && isset($sourceFrom)) { $method = $method . $indexFrom; - $sourceObject = $service->$method($source->$indexFrom); + $sourceObject = $service->$method($sourceFrom); } if ($sourceObject && isset($sourceType)) { From 4b72e970b89137d4aa9291155bb0746fba6a9279 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Tue, 3 Nov 2015 10:27:36 +0100 Subject: [PATCH 09/19] Added hook for schematic field models --- README.md | 11 +++++++++ models/Schematic_FieldFactoryModel.php | 34 +++++++++++++++++++++++--- phpunit.xml.dist | 1 + 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0043c497..0e510be3 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,17 @@ public function registerMigrationService() } ``` +* Has a hook to add mappings for custom field types, the Plugin_CustomSchematicFieldModel must extend the Schematic_FieldModel + +```php +public function registerSchematicFieldModels() +{ + return array( + 'fieldType' => Plugin_CustomSchematicFieldModel + ); +} +``` + ## Changelog ###1.3.0### diff --git a/models/Schematic_FieldFactoryModel.php b/models/Schematic_FieldFactoryModel.php index 85f3fa33..f23bb1c3 100644 --- a/models/Schematic_FieldFactoryModel.php +++ b/models/Schematic_FieldFactoryModel.php @@ -2,8 +2,18 @@ namespace Craft; +/** + * Class Schematic_FieldFactoryModel + */ class Schematic_FieldFactoryModel { + /** + * @return PluginsService + */ + private function getPluginsService() + { + return craft()->plugins; + } /** * @param array $fieldDefinition @@ -38,12 +48,28 @@ public function getDefinition(FieldModel $field, $includeContext = true) */ private function getSchematicFieldModel($fieldType) { - $className = 'Craft\Schematic_' . ucfirst($fieldType) . 'FieldModel'; + $fieldModel = new Schematic_FieldModel(); + $classNames = array(); + $customFieldMappings = $this->getPluginsService()->call('registerSchematicFieldModels'); + + foreach ($customFieldMappings as $mappings) { + if (array_key_exists($fieldType, $mappings)) { + $classNames[] = $mappings[$fieldType]; + } + } + + $classNames[] = 'Craft\Schematic_' . ucfirst($fieldType) . 'FieldModel'; - if (class_exists($className)) { - return new $className; + foreach($classNames as $className){ + if (class_exists($className)) { + $tmpFieldModel = new $className; + if($tmpFieldModel instanceof Schematic_FieldModel){ + $fieldModel = $tmpFieldModel; + break; + } + } } - return new Schematic_FieldModel(); + return $fieldModel; } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 19f5544f..edd9864d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -15,6 +15,7 @@ + ./models ./services From 4cfff0a025abbdc006f31ac3ca51d06e070624c1 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Tue, 3 Nov 2015 10:30:02 +0100 Subject: [PATCH 10/19] PSR-2: Added enter before return statement --- models/Schematic_SuperTableFieldModel.php | 1 + 1 file changed, 1 insertion(+) diff --git a/models/Schematic_SuperTableFieldModel.php b/models/Schematic_SuperTableFieldModel.php index 0d612513..6224e6d9 100644 --- a/models/Schematic_SuperTableFieldModel.php +++ b/models/Schematic_SuperTableFieldModel.php @@ -57,6 +57,7 @@ protected function getBlockTypes(array $fieldDefinition, FieldModel $field) $this->populateBlockType($field, $blockType, $blockTypeDef); $blockTypes[] = $blockType; } + return $blockTypes; } From 3b8a6afbf2b850b54c4086f8b4519ca37da2ed48 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Tue, 3 Nov 2015 10:48:45 +0100 Subject: [PATCH 11/19] Expanded sources method to also handle folder sources --- models/Schematic_FieldModel.php | 27 ++++++++++++++++------ models/Schematic_SuperTableFieldModel.php | 2 +- services/Schematic_AssetsService.php | 28 ++++++++++++++++++++++- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/models/Schematic_FieldModel.php b/models/Schematic_FieldModel.php index 290dd10d..56665b66 100644 --- a/models/Schematic_FieldModel.php +++ b/models/Schematic_FieldModel.php @@ -31,6 +31,14 @@ private function getUserGroupsService() return craft()->userGroups; } + /** + * @return Schematic_AssetsService + */ + private function getAssetsService() + { + return craft()->schematic_assets; + } + /** * @param FieldModel $field * @param $includeContext @@ -96,13 +104,12 @@ public function populate(array $fieldDefinition, FieldModel $field, $fieldHandle */ private function getMappedSources($sources, $indexFrom, $indexTo) { - if (!is_array($sources)) { - return $sources; - } - - $mappedSources = array(); - foreach ($sources as $source) { - $mappedSources[] = $this->getSource($source, $indexFrom, $indexTo); + $mappedSources = $sources; + if (is_array($sources)) { + $mappedSources = array(); + foreach ($sources as $source) { + $mappedSources[] = $this->getSource($source, $indexFrom, $indexTo); + } } return $mappedSources; @@ -110,6 +117,8 @@ private function getMappedSources($sources, $indexFrom, $indexTo) /** * Gets a source by the attribute indexFrom, and returns it with attribute $indexTo + * @TODO Break up and simplify this method + * * @param string $source * @param string $indexFrom * @param string $indexTo @@ -131,6 +140,10 @@ private function getSource($source, $indexFrom, $indexTo) $service = $this->getUserGroupsService(); $method = 'getGroupBy'; break; + case 'folder': + $service = $this->getAssetsService(); + $method = 'getSourceTypeBy'; + break; } } elseif ($source !== 'singles') { //Backwards compatibility diff --git a/models/Schematic_SuperTableFieldModel.php b/models/Schematic_SuperTableFieldModel.php index 6224e6d9..a3dbac29 100644 --- a/models/Schematic_SuperTableFieldModel.php +++ b/models/Schematic_SuperTableFieldModel.php @@ -57,7 +57,7 @@ protected function getBlockTypes(array $fieldDefinition, FieldModel $field) $this->populateBlockType($field, $blockType, $blockTypeDef); $blockTypes[] = $blockType; } - + return $blockTypes; } diff --git a/services/Schematic_AssetsService.php b/services/Schematic_AssetsService.php index eeaba2e3..8ec080cc 100644 --- a/services/Schematic_AssetsService.php +++ b/services/Schematic_AssetsService.php @@ -15,6 +15,32 @@ */ class Schematic_AssetsService extends Schematic_AbstractService { + /** + * @return AssetSourcesService + */ + private function getAssetSourcesService() + { + return craft()->assetSources; + } + + /** + * @param $sourceTypeId + * @return array|mixed|null + */ + public function getSourceTypeById($sourceTypeId) + { + return AssetSourceRecord::model()->findByAttributes(array('id' => $sourceTypeId)); + } + + /** + * @param $sourceTypeHandle + * @return array|mixed|null + */ + public function getSourceTypeByHandle($sourceTypeHandle) + { + return AssetSourceRecord::model()->findByAttributes(array('handle' => $sourceTypeHandle)); + } + /** * Import asset source definitions. * @@ -69,7 +95,7 @@ private function populateAssetSource($assetHandle, array $assetSourceDefinition) */ public function export(array $data = array()) { - $assetSources = craft()->assetSources->getAllSources(); + $assetSources = $this->getAssetSourcesService()->getAllSources(); $assetSourceDefinitions = array(); foreach ($assetSources as $assetSource) { From 0e7623c64f5ff893470b623353968d9a2ec1c706 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Tue, 3 Nov 2015 10:56:15 +0100 Subject: [PATCH 12/19] Sort permissions --- services/Schematic_UserGroupsService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/services/Schematic_UserGroupsService.php b/services/Schematic_UserGroupsService.php index d0737014..b6d0fc03 100644 --- a/services/Schematic_UserGroupsService.php +++ b/services/Schematic_UserGroupsService.php @@ -134,6 +134,7 @@ private function getGroupPermissionDefinitions($group) $permissionDefinitions[] = $this->getPermissionDefinition($permission); } } + sort($permissionDefinitions); return $permissionDefinitions; } From 93bb4c6d5d5ef031bdecefda45b5519175da1720 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Tue, 3 Nov 2015 11:05:27 +0100 Subject: [PATCH 13/19] Fix for usergroupsservice test --- tests/Schematic_UserGroupsServiceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Schematic_UserGroupsServiceTest.php b/tests/Schematic_UserGroupsServiceTest.php index 1cb5cf68..0884fcbd 100644 --- a/tests/Schematic_UserGroupsServiceTest.php +++ b/tests/Schematic_UserGroupsServiceTest.php @@ -194,9 +194,9 @@ public function provideValidUserGroups() 'name' => 'groupName1', 'permissions' => array( 'accessSiteWhenSystemIsOff', - 'performUpdates', 'editEntries:sectionHandle1', 'editGlobalSet:globalSetHandle1', + 'performUpdates', 'viewAssetSource:assetSourceHandle1', ), ) From 0bbe7f077e56d249d91dec5e526f9a508ba13f0e Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Tue, 3 Nov 2015 11:14:14 +0100 Subject: [PATCH 14/19] Moved test classes to subfolder --- .../Schematic_PluginsServiceTest.php | 8 +++--- .../Schematic_SchematicServiceTest.php | 26 +++++++++---------- .../Schematic_UserGroupsServiceTest.php | 8 +++--- .../Schematic_UsersServiceTest.php | 10 +++---- 4 files changed, 26 insertions(+), 26 deletions(-) rename tests/{ => services}/Schematic_PluginsServiceTest.php (96%) rename tests/{ => services}/Schematic_SchematicServiceTest.php (88%) rename tests/{ => services}/Schematic_UserGroupsServiceTest.php (98%) rename tests/{ => services}/Schematic_UsersServiceTest.php (94%) diff --git a/tests/Schematic_PluginsServiceTest.php b/tests/services/Schematic_PluginsServiceTest.php similarity index 96% rename from tests/Schematic_PluginsServiceTest.php rename to tests/services/Schematic_PluginsServiceTest.php index 16aebbe5..b2a3a274 100644 --- a/tests/Schematic_PluginsServiceTest.php +++ b/tests/services/Schematic_PluginsServiceTest.php @@ -38,10 +38,10 @@ public function setUp() public static function setUpBeforeClass() { parent::setUpBeforeClass(); - require_once __DIR__.'/../SchematicPlugin.php'; - require_once __DIR__.'/../models/Schematic_ResultModel.php'; - require_once __DIR__.'/../services/Schematic_AbstractService.php'; - require_once __DIR__.'/../services/Schematic_PluginsService.php'; + require_once __DIR__.'/../../SchematicPlugin.php'; + require_once __DIR__.'/../../models/Schematic_ResultModel.php'; + require_once __DIR__.'/../../services/Schematic_AbstractService.php'; + require_once __DIR__.'/../../services/Schematic_PluginsService.php'; } /** diff --git a/tests/Schematic_SchematicServiceTest.php b/tests/services/Schematic_SchematicServiceTest.php similarity index 88% rename from tests/Schematic_SchematicServiceTest.php rename to tests/services/Schematic_SchematicServiceTest.php index f791fd92..8fe876a1 100644 --- a/tests/Schematic_SchematicServiceTest.php +++ b/tests/services/Schematic_SchematicServiceTest.php @@ -40,18 +40,18 @@ public function setUp() public static function setUpBeforeClass() { parent::setUpBeforeClass(); - require_once __DIR__.'/../SchematicPlugin.php'; - require_once __DIR__.'/../models/Schematic_DataModel.php'; - require_once __DIR__.'/../models/Schematic_ResultModel.php'; - require_once __DIR__.'/../services/Schematic_AbstractService.php'; - require_once __DIR__.'/../services/Schematic_AssetsService.php'; - require_once __DIR__.'/../services/Schematic_FieldsService.php'; - require_once __DIR__.'/../services/Schematic_GlobalsService.php'; - require_once __DIR__.'/../services/Schematic_PluginsService.php'; - require_once __DIR__.'/../services/Schematic_SectionsService.php'; - require_once __DIR__.'/../services/Schematic_UserGroupsService.php'; - require_once __DIR__.'/../services/Schematic_UsersService.php'; - require_once __DIR__.'/../services/SchematicService.php'; + require_once __DIR__.'/../../SchematicPlugin.php'; + require_once __DIR__.'/../../models/Schematic_DataModel.php'; + require_once __DIR__.'/../../models/Schematic_ResultModel.php'; + require_once __DIR__.'/../../services/Schematic_AbstractService.php'; + require_once __DIR__.'/../../services/Schematic_AssetsService.php'; + require_once __DIR__.'/../../services/Schematic_FieldsService.php'; + require_once __DIR__.'/../../services/Schematic_GlobalsService.php'; + require_once __DIR__.'/../../services/Schematic_PluginsService.php'; + require_once __DIR__.'/../../services/Schematic_SectionsService.php'; + require_once __DIR__.'/../../services/Schematic_UserGroupsService.php'; + require_once __DIR__.'/../../services/Schematic_UsersService.php'; + require_once __DIR__.'/../../services/SchematicService.php'; } /** @@ -59,7 +59,7 @@ public static function setUpBeforeClass() */ private function getYamlTestFile() { - return __DIR__ . '/data/test_schema.yml'; + return __DIR__ . '/../data/test_schema.yml'; } /** diff --git a/tests/Schematic_UserGroupsServiceTest.php b/tests/services/Schematic_UserGroupsServiceTest.php similarity index 98% rename from tests/Schematic_UserGroupsServiceTest.php rename to tests/services/Schematic_UserGroupsServiceTest.php index 0884fcbd..ae0fed4a 100644 --- a/tests/Schematic_UserGroupsServiceTest.php +++ b/tests/services/Schematic_UserGroupsServiceTest.php @@ -26,10 +26,10 @@ class Schematic_UserGroupsServiceTest extends BaseTest public static function setUpBeforeClass() { parent::setUpBeforeClass(); - require_once __DIR__.'/../SchematicPlugin.php'; - require_once __DIR__.'/../models/Schematic_ResultModel.php'; - require_once __DIR__.'/../services/Schematic_AbstractService.php'; - require_once __DIR__.'/../services/Schematic_UserGroupsService.php'; + require_once __DIR__.'/../../SchematicPlugin.php'; + require_once __DIR__.'/../../models/Schematic_ResultModel.php'; + require_once __DIR__.'/../../services/Schematic_AbstractService.php'; + require_once __DIR__.'/../../services/Schematic_UserGroupsService.php'; } //============================================================================================================== diff --git a/tests/Schematic_UsersServiceTest.php b/tests/services/Schematic_UsersServiceTest.php similarity index 94% rename from tests/Schematic_UsersServiceTest.php rename to tests/services/Schematic_UsersServiceTest.php index a42aba35..c2282da1 100644 --- a/tests/Schematic_UsersServiceTest.php +++ b/tests/services/Schematic_UsersServiceTest.php @@ -38,11 +38,11 @@ public function setUp() public static function setUpBeforeClass() { parent::setUpBeforeClass(); - require_once __DIR__.'/../SchematicPlugin.php'; - require_once __DIR__.'/../models/Schematic_ResultModel.php'; - require_once __DIR__.'/../services/Schematic_AbstractService.php'; - require_once __DIR__.'/../services/Schematic_UsersService.php'; - require_once __DIR__.'/../services/Schematic_FieldsService.php'; + require_once __DIR__.'/../../SchematicPlugin.php'; + require_once __DIR__.'/../../models/Schematic_ResultModel.php'; + require_once __DIR__.'/../../services/Schematic_AbstractService.php'; + require_once __DIR__.'/../../services/Schematic_UsersService.php'; + require_once __DIR__.'/../../services/Schematic_FieldsService.php'; } /** From 40bf4241367d08128b38bf0d4ff4db86a0872c44 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Tue, 3 Nov 2015 11:40:29 +0100 Subject: [PATCH 15/19] Bumped version --- README.md | 5 +++++ SchematicPlugin.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0e510be3..57f582a6 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ public function registerSchematicFieldModels() ## Changelog +###1.4.0### + - Reworked importing and exporting of fields + - Added hook to allow the addition of custom logic for importing and exporting fields + - Permissions are now sorted + ###1.3.0### - Added the ability to use an override file diff --git a/SchematicPlugin.php b/SchematicPlugin.php index 7cfb0f96..63488fab 100644 --- a/SchematicPlugin.php +++ b/SchematicPlugin.php @@ -32,7 +32,7 @@ public function getName() */ public function getVersion() { - return '1.3.0'; + return '1.4.0'; } /** From 86eb84880ca867471f7305624df1c529d1bc7c58 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Tue, 3 Nov 2015 11:51:09 +0100 Subject: [PATCH 16/19] Rename MockObject to Mock --- .../Schematic_UserGroupsServiceTest.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/services/Schematic_UserGroupsServiceTest.php b/tests/services/Schematic_UserGroupsServiceTest.php index ae0fed4a..da5b1f3d 100644 --- a/tests/services/Schematic_UserGroupsServiceTest.php +++ b/tests/services/Schematic_UserGroupsServiceTest.php @@ -2,7 +2,7 @@ namespace Craft; -use PHPUnit_Framework_MockObject_MockObject as MockObject; +use PHPUnit_Framework_MockObject_MockObject as Mock; /** * Class Schematic_PluginsServiceTest @@ -245,7 +245,7 @@ public function provideValidUserGroupDefinitions() /** * @param string $groupId - * @return MockObject|UserGroupModel + * @return Mock|UserGroupModel */ private function getMockUserGroup($groupId) { @@ -272,7 +272,7 @@ private function getMockUserGroup($groupId) /** * @param $indexBy - * @return MockObject|SectionsService + * @return Mock|SectionsService */ private function setMockSectionsService($indexBy) { @@ -293,7 +293,7 @@ private function setMockSectionsService($indexBy) /** * @param string $indexBy * @param int $count - * @return MockObject[]|SectionModel[] + * @return Mock[]|SectionModel[] */ private function getMockSections($indexBy, $count) { @@ -319,7 +319,7 @@ private function getMockSections($indexBy, $count) /** * @param string $indexBy - * @return MockObject|AssetSourcesService + * @return Mock|AssetSourcesService */ private function setMockAssetSourcesService($indexBy) { @@ -340,7 +340,7 @@ private function setMockAssetSourcesService($indexBy) /** * @param string $indexBy * @param int $count - * @return MockObject[]|AssetSourceModel[] + * @return Mock[]|AssetSourceModel[] */ private function getMockAssetSources($indexBy, $count) { @@ -366,7 +366,7 @@ private function getMockAssetSources($indexBy, $count) /** * @param string $indexBy - * @return MockObject|AssetSourcesService + * @return Mock|AssetSourcesService */ private function setMockGlobalsService($indexBy) { @@ -387,7 +387,7 @@ private function setMockGlobalsService($indexBy) /** * @param string $indexBy * @param int $count - * @return MockObject[]|GlobalSetModel[] + * @return Mock[]|GlobalSetModel[] */ private function getMockGlobalSets($indexBy, $count) { @@ -413,7 +413,7 @@ private function getMockGlobalSets($indexBy, $count) /** * @param bool $success - * @return UserGroupsService|MockObject + * @return UserGroupsService|Mock */ private function setMockUserGroupsService($success = true) { @@ -452,7 +452,7 @@ private function getMockUserGroups($count) /** * @param array $permissions * @param bool $success - * @return UserPermissionsService|MockObject + * @return UserPermissionsService|Mock */ private function setMockUserPermissionsService(array $permissions = array(), $success = true) { From ef0003ea90004b3b0d9acf315167d470e4e225d4 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Tue, 3 Nov 2015 13:28:27 +0100 Subject: [PATCH 17/19] Reduced logic in fieldfactory and wrote test for the remaining logic --- models/Schematic_FieldFactoryModel.php | 29 +--- models/Schematic_FieldModel.php | 2 +- models/Schematic_MatrixFieldModel.php | 6 +- models/Schematic_SuperTableFieldModel.php | 6 +- services/Schematic_FieldsService.php | 6 +- .../Schematic_FieldFactoryModelTest.php | 150 ++++++++++++++++++ 6 files changed, 164 insertions(+), 35 deletions(-) create mode 100644 tests/models/Schematic_FieldFactoryModelTest.php diff --git a/models/Schematic_FieldFactoryModel.php b/models/Schematic_FieldFactoryModel.php index f23bb1c3..c8cbab71 100644 --- a/models/Schematic_FieldFactoryModel.php +++ b/models/Schematic_FieldFactoryModel.php @@ -15,38 +15,11 @@ private function getPluginsService() return craft()->plugins; } - /** - * @param array $fieldDefinition - * @param FieldModel $field - * @param string $fieldHandle - * @param FieldGroupModel|null $group - * @return FieldModel - */ - public function populate(array $fieldDefinition, FieldModel $field, $fieldHandle, FieldGroupModel $group = null) - { - $schematicFieldModel = $this->getSchematicFieldModel($fieldDefinition['type']); - $schematicFieldModel->populate($fieldDefinition, $field, $fieldHandle, $group); - - return $field; - } - - /** - * @param FieldModel $field - * @param bool|false $includeContext - * @return array - */ - public function getDefinition(FieldModel $field, $includeContext = true) - { - $schematicFieldModel = $this->getSchematicFieldModel($field->type); - - return $schematicFieldModel->getDefinition($field, $includeContext); - } - /** * @param $fieldType * @return Schematic_FieldModel */ - private function getSchematicFieldModel($fieldType) + public function build($fieldType) { $fieldModel = new Schematic_FieldModel(); $classNames = array(); diff --git a/models/Schematic_FieldModel.php b/models/Schematic_FieldModel.php index 56665b66..2f9487a6 100644 --- a/models/Schematic_FieldModel.php +++ b/models/Schematic_FieldModel.php @@ -10,7 +10,7 @@ class Schematic_FieldModel /** * @return Schematic_FieldFactoryModel */ - public function getFieldFactory() + protected function getFieldFactory() { return craft()->schematic_fields->getFieldFactory(); } diff --git a/models/Schematic_MatrixFieldModel.php b/models/Schematic_MatrixFieldModel.php index 55fd475e..00df5a19 100644 --- a/models/Schematic_MatrixFieldModel.php +++ b/models/Schematic_MatrixFieldModel.php @@ -52,7 +52,8 @@ protected function getBlockTypeDefinitions(FieldModel $field) $blockTypeFieldDefinitions = array(); foreach ($blockType->getFields() as $blockTypeField) { - $blockTypeFieldDefinitions[$blockTypeField->handle] = $fieldFactory->getDefinition($blockTypeField, false); + $schematicFieldModel = $fieldFactory->build($blockTypeField->type); + $blockTypeFieldDefinitions[$blockTypeField->handle] = $schematicFieldModel->getDefinition($blockTypeField, false); } $blockTypeDefinitions[$blockType->handle] = array( @@ -138,7 +139,8 @@ private function populateBlockType(FieldModel $field, MatrixBlockTypeModel $bloc ? $blockTypeFields[$blockTypeFieldHandle] : new FieldModel(); - $fieldFactory->populate($blockTypeFieldDef, $blockTypeField, $blockTypeFieldHandle); + $schematicFieldModel = $fieldFactory->build($blockTypeFieldDef['type']); + $schematicFieldModel->populate($blockTypeFieldDef, $blockTypeField, $blockTypeFieldHandle); $newBlockTypeFields[] = $blockTypeField; } diff --git a/models/Schematic_SuperTableFieldModel.php b/models/Schematic_SuperTableFieldModel.php index a3dbac29..a6e378e3 100644 --- a/models/Schematic_SuperTableFieldModel.php +++ b/models/Schematic_SuperTableFieldModel.php @@ -33,7 +33,8 @@ protected function getBlockTypeDefinitions(FieldModel $field) $blockTypeFieldDefinitions = array(); foreach ($blockType->getFields() as $blockTypeField) { - $blockTypeFieldDefinitions[$blockTypeField->handle] = $fieldFactory->getDefinition($blockTypeField, false); + $schematicFieldModel = $fieldFactory->build($blockTypeField->type); + $blockTypeFieldDefinitions[$blockTypeField->handle] = $schematicFieldModel->getDefinition($blockTypeField, false); } $blockTypeDefinitions[] = array( @@ -84,7 +85,8 @@ private function populateBlockType(FieldModel $field, SuperTable_BlockTypeModel ? $blockTypeFields[$blockTypeFieldHandle] : new FieldModel(); - $fieldFactory->populate($blockTypeFieldDef, $blockTypeField, $blockTypeFieldHandle); + $schematicFieldModel = $fieldFactory->build($blockTypeFieldDef['type']); + $schematicFieldModel->populate($blockTypeFieldDef, $blockTypeField, $blockTypeFieldHandle); $newBlockTypeFields[] = $blockTypeField; } diff --git a/services/Schematic_FieldsService.php b/services/Schematic_FieldsService.php index dcc0648f..d668a6ff 100644 --- a/services/Schematic_FieldsService.php +++ b/services/Schematic_FieldsService.php @@ -101,7 +101,8 @@ public function export(array $groups = array()) private function getFieldDefinition(FieldModel $field) { $fieldFactory = $this->getFieldFactory(); - $definition = $fieldFactory->getDefinition($field); + $schematicFieldModel = $fieldFactory->build($field->type); + $definition = $schematicFieldModel->getDefinition($field, true); return $definition; } @@ -279,7 +280,8 @@ private function importFields(array $fieldDefinitions, FieldGroupModel $group) foreach ($fieldDefinitions as $fieldHandle => $fieldDef) { $field = $this->getFieldModel($fieldHandle); - $fieldFactory->populate($fieldDef, $field, $fieldHandle, $group); + $schematicFieldModel = $fieldFactory->build($fieldDef['type']); + $schematicFieldModel->populate($fieldDef, $field, $fieldHandle, $group); $this->saveFieldModel($field); } } diff --git a/tests/models/Schematic_FieldFactoryModelTest.php b/tests/models/Schematic_FieldFactoryModelTest.php new file mode 100644 index 00000000..61095ad7 --- /dev/null +++ b/tests/models/Schematic_FieldFactoryModelTest.php @@ -0,0 +1,150 @@ + + */ +class Schematic_FieldFactoryModelTest extends BaseTest +{ + + /** + * {@inheritdoc} + */ + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + require_once __DIR__.'/../../models/Schematic_FieldFactoryModel.php'; + require_once __DIR__.'/../../models/Schematic_FieldModel.php'; + require_once __DIR__.'/../../models/Schematic_MatrixFieldModel.php'; + require_once __DIR__.'/../../models/Schematic_PositionSelectFieldModel.php'; + require_once __DIR__.'/../../models/Schematic_SuperTableFieldModel.php'; + } + + /** + * @covers ::build + * @dataProvider provideFieldTypes + * + * @param string $fieldType + * @param string $expectedClassName + */ + public function testBuildWithDefaultFieldTypesReturnsCorrectClass($fieldType, $expectedClassName) + { + $fieldFactory = new Schematic_FieldFactoryModel(); + $schematicFieldModel = $fieldFactory->build($fieldType); + + $this->assertEquals($expectedClassName, get_class($schematicFieldModel)); + } + + /** + * @covers ::build + * @dataProvider provideHookedFieldTypes + * + * @param string $fieldType + * @param string $expectedClassName + * @param array $hookCallResults + */ + public function testBuildWithFieldHook($fieldType, $expectedClassName, array $hookCallResults) + { + $this->setMockPluginsService($hookCallResults); + + $fieldFactory = new Schematic_FieldFactoryModel(); + $schematicFieldModel = $fieldFactory->build($fieldType); + + $this->assertInstanceOf($expectedClassName, $schematicFieldModel); + } + + /** + * @return array + */ + public function provideFieldTypes() + { + return array( + // Base fields + 'Assets' => array('Assets', 'Craft\Schematic_FieldModel'), + 'Categories' => array('Category', 'Craft\Schematic_FieldModel'), + 'Checkboxes' => array('Checkboxes', 'Craft\Schematic_FieldModel'), + 'Color' => array('Color', 'Craft\Schematic_FieldModel'), + 'Date' => array('Date', 'Craft\Schematic_FieldModel'), + 'Dropdown' => array('Dropdown', 'Craft\Schematic_FieldModel'), + 'Entries' => array('Entries', 'Craft\Schematic_FieldModel'), + 'Lightswitch' => array('Lightswitch', 'Craft\Schematic_FieldModel'), + 'Matrix' => array('Matrix', 'Craft\Schematic_MatrixFieldModel'), + 'MultiSelect' => array('Multiselect', 'Craft\Schematic_FieldModel'), + 'Number' => array('Number', 'Craft\Schematic_FieldModel'), + 'PlainText' => array('PlainText', 'Craft\Schematic_FieldModel'), + 'PositionSelect' => array('PositionSelect', 'Craft\Schematic_PositionSelectFieldModel'), + 'RadioButtons' => array('RadioButtons', 'Craft\Schematic_FieldModel'), + 'RichText' => array('RichText', 'Craft\Schematic_FieldModel'), + 'Table' => array('Table', 'Craft\Schematic_FieldModel'), + 'Tags' => array('Tags', 'Craft\Schematic_FieldModel'), + 'Users' => array('Users', 'Craft\Schematic_FieldModel'), + // Plugin fields + 'SuperTable' => array('SuperTable', 'Craft\Schematic_SuperTableFieldModel'), + ); + } + + /** + * @return array + */ + public function provideHookedFieldTypes() + { + return array( + 'color mapped to matrix field model' => array( + 'fieldType' => 'Color', + 'expectedClassName' => 'Craft\Schematic_MatrixFieldModel', + 'hookCallResults' => array( + 'plugin1' => array( + 'Color' => 'Craft\Schematic_MatrixFieldModel' + ) + ) + ), + 'color mapped to wrong class type' => array( + 'fieldType' => 'Color', + 'expectedClassName' => 'Craft\Schematic_FieldModel', + 'hookCallResults' => array( + 'plugin1' => array( + 'Color' => 'Craft\ColorFieldType' + ) + ) + ), + 'something mapped to matrix field model' => array( + 'fieldType' => 'PlainText', + 'expectedClassName' => 'Craft\Schematic_FieldModel', + 'hookCallResults' => array( + 'plugin1' => array( + 'Color' => 'Craft\Schematic_MatrixFieldModel' + ) + ) + ) + ); + } + + /** + * @param array $schematicFieldModels + */ + private function setMockPluginsService( array $schematicFieldModels ) + { + $mockPluginsService = $this->getMockBuilder('Craft\PluginsService') + ->disableOriginalConstructor() + ->getMock(); + + $mockPluginsService->expects($this->exactly(1)) + ->method('call') + ->with('registerSchematicFieldModels') + ->willReturn($schematicFieldModels); + + $this->setComponent(craft(), 'plugins', $mockPluginsService); + } +} From b1d581ee1e1ba7cfae322c87da4663cc91fa3d46 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Tue, 3 Nov 2015 14:07:43 +0100 Subject: [PATCH 18/19] Fix for not overriding of supertable blocktypes --- models/Schematic_MatrixFieldModel.php | 2 +- models/Schematic_SuperTableFieldModel.php | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/models/Schematic_MatrixFieldModel.php b/models/Schematic_MatrixFieldModel.php index 00df5a19..441fc4ea 100644 --- a/models/Schematic_MatrixFieldModel.php +++ b/models/Schematic_MatrixFieldModel.php @@ -96,7 +96,7 @@ public function populate(array $fieldDefinition, FieldModel $field, $fieldHandle */ protected function getBlockTypes(array $fieldDefinition, FieldModel $field) { - $blockTypes = craft()->matrix->getBlockTypesByFieldId($field->id, 'handle'); + $blockTypes = $this->getMatrixService()->getBlockTypesByFieldId($field->id, 'handle'); foreach ($fieldDefinition['blockTypes'] as $blockTypeHandle => $blockTypeDef) { $blockType = array_key_exists($blockTypeHandle, $blockTypes) diff --git a/models/Schematic_SuperTableFieldModel.php b/models/Schematic_SuperTableFieldModel.php index a6e378e3..29e56903 100644 --- a/models/Schematic_SuperTableFieldModel.php +++ b/models/Schematic_SuperTableFieldModel.php @@ -52,11 +52,18 @@ protected function getBlockTypeDefinitions(FieldModel $field) */ protected function getBlockTypes(array $fieldDefinition, FieldModel $field) { - $blockTypes = array(); - foreach ($fieldDefinition['blockTypes'] as $blockTypeId => $blockTypeDef) { - $blockType = new SuperTable_BlockTypeModel(); + $blockTypes = $this->getSuperTableService()->getBlockTypesByFieldId($field->id); + + $index = 0; + foreach ($fieldDefinition['blockTypes'] as $blockTypeDef) { + $blockType = array_key_exists($index, $blockTypes) + ? $blockTypes[$index] + : new SuperTable_BlockTypeModel(); + $this->populateBlockType($field, $blockType, $blockTypeDef); - $blockTypes[] = $blockType; + + $blockTypes[$index] = $blockType; + $index++; } return $blockTypes; From 24a0672ad4b234e49f12065d52a515315ca871f4 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Tue, 3 Nov 2015 14:16:04 +0100 Subject: [PATCH 19/19] Docblock fixes --- models/Schematic_FieldFactoryModel.php | 10 +++++++++- models/Schematic_FieldModel.php | 10 +++++++++- models/Schematic_MatrixFieldModel.php | 10 +++++++++- models/Schematic_PositionSelectFieldModel.php | 10 +++++++++- models/Schematic_SuperTableFieldModel.php | 10 +++++++++- 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/models/Schematic_FieldFactoryModel.php b/models/Schematic_FieldFactoryModel.php index c8cbab71..816d2f59 100644 --- a/models/Schematic_FieldFactoryModel.php +++ b/models/Schematic_FieldFactoryModel.php @@ -3,7 +3,15 @@ namespace Craft; /** - * Class Schematic_FieldFactoryModel + * Schematic Field Factory Model. + * + * Provides a schematic field model for mapping data + * + * @author Nerds & Company + * @copyright Copyright (c) 2015, Nerds & Company + * @license MIT + * + * @link http://www.nerds.company */ class Schematic_FieldFactoryModel { diff --git a/models/Schematic_FieldModel.php b/models/Schematic_FieldModel.php index 2f9487a6..ddc11f6f 100644 --- a/models/Schematic_FieldModel.php +++ b/models/Schematic_FieldModel.php @@ -3,7 +3,15 @@ namespace Craft; /** - * Class Schematic_FieldModel + * Schematic Field Model. + * + * A schematic field model for mapping data + * + * @author Nerds & Company + * @copyright Copyright (c) 2015, Nerds & Company + * @license MIT + * + * @link http://www.nerds.company */ class Schematic_FieldModel { diff --git a/models/Schematic_MatrixFieldModel.php b/models/Schematic_MatrixFieldModel.php index 441fc4ea..9ca3f299 100644 --- a/models/Schematic_MatrixFieldModel.php +++ b/models/Schematic_MatrixFieldModel.php @@ -3,7 +3,15 @@ namespace Craft; /** - * Class Schematic_MatrixFieldModel + * Schematic Matrix Field Model. + * + * A schematic field model for mapping matrix data + * + * @author Nerds & Company + * @copyright Copyright (c) 2015, Nerds & Company + * @license MIT + * + * @link http://www.nerds.company */ class Schematic_MatrixFieldModel extends Schematic_FieldModel { diff --git a/models/Schematic_PositionSelectFieldModel.php b/models/Schematic_PositionSelectFieldModel.php index 71b006be..22fadf0d 100644 --- a/models/Schematic_PositionSelectFieldModel.php +++ b/models/Schematic_PositionSelectFieldModel.php @@ -3,7 +3,15 @@ namespace Craft; /** - * Class Schematic_MatrixFieldModel + * Schematic Position Select Field Model. + * + * A schematic field model for mapping position select data + * + * @author Nerds & Company + * @copyright Copyright (c) 2015, Nerds & Company + * @license MIT + * + * @link http://www.nerds.company */ class Schematic_PositionSelectFieldModel extends Schematic_FieldModel { diff --git a/models/Schematic_SuperTableFieldModel.php b/models/Schematic_SuperTableFieldModel.php index 29e56903..8217d509 100644 --- a/models/Schematic_SuperTableFieldModel.php +++ b/models/Schematic_SuperTableFieldModel.php @@ -3,7 +3,15 @@ namespace Craft; /** - * Class Schematic_SuperTableFieldModel + * Schematic Super Table Field Model. + * + * A schematic field model for mapping super table data + * + * @author Nerds & Company + * @copyright Copyright (c) 2015, Nerds & Company + * @license MIT + * + * @link http://www.nerds.company */ class Schematic_SuperTableFieldModel extends Schematic_MatrixFieldModel {