public function import($fields)
 {
     $fieldTypes = craft()->fields->getAllFieldTypes();
     $errors = array();
     foreach ($fields as $fieldInfo) {
         if (array_key_exists($fieldInfo['type'], $fieldTypes)) {
             $field = new FieldModel();
             $field->setAttributes(array('groupId' => $fieldInfo['groupId'], 'name' => $fieldInfo['name'], 'handle' => $fieldInfo['handle'], 'instructions' => $fieldInfo['instructions'], 'translatable' => $fieldInfo['translatable'], 'required' => $fieldInfo['required'], 'type' => $fieldInfo['type'], 'settings' => $fieldInfo['settings']));
             // Send off to Craft's native fieldSave service for heavy lifting.
             if (craft()->fields->saveField($field)) {
                 FieldManagerPlugin::log($field->name . ' imported successfully.');
             } else {
                 $errors[$fieldInfo['handle']] = $field;
                 FieldManagerPlugin::log('Could not import ' . $field->name . ' - ' . print_r($field->getErrors(), true), LogLevel::Error);
             }
         }
     }
     return $errors;
 }
 public function import($fieldDefs)
 {
     $fields = craft()->fields->getAllFields('handle');
     $fieldTypes = craft()->fields->getAllFieldTypes();
     foreach ($fieldDefs as $fieldHandle => $fieldDef) {
         if (array_key_exists($fieldDef['type'], $fieldTypes)) {
             $field = new FieldModel();
             $field->setAttributes(array('handle' => $fieldHandle, 'groupId' => $fieldDef['groupId'], 'name' => $fieldDef['name'], 'context' => $fieldDef['context'], 'instructions' => $fieldDef['instructions'], 'translatable' => $fieldDef['translatable'], 'type' => $fieldDef['type'], 'settings' => $fieldDef['settings']));
             if ($field->type == 'PositionSelect') {
                 $this->handlePositionSelect($fieldDef, $field);
             }
             if (!craft()->fields->saveField($field)) {
                 return $field->getAllErrors();
             }
             if ($field->type == 'Matrix') {
                 $this->handleMatrixImport($fieldDef, $field);
             }
             if ($field->type == 'SuperTable') {
                 $this->handleSuperTableImport($fieldDef, $field);
             }
         }
     }
     return true;
 }