public function prepSettings($settings) { if ($settings instanceof SuperTable_SettingsModel) { return $settings; } $superTableSettings = new SuperTable_SettingsModel($this->model); $blockTypes = array(); $columns = array(); if (!empty($settings['blockTypes'])) { foreach ($settings['blockTypes'] as $blockTypeId => $blockTypeSettings) { $blockType = new SuperTable_BlockTypeModel(); $blockType->id = $blockTypeId; $blockType->fieldId = $this->model->id; $fields = array(); if (!empty($blockTypeSettings['fields'])) { foreach ($blockTypeSettings['fields'] as $fieldId => $fieldSettings) { $field = new FieldModel(); $field->id = $fieldId; $field->name = $fieldSettings['name']; $field->handle = $fieldSettings['handle']; $field->instructions = $fieldSettings['instructions']; $field->required = !empty($fieldSettings['required']); $field->translatable = !empty($fieldSettings['translatable']); $field->type = $fieldSettings['type']; if (isset($fieldSettings['width'])) { $columns[$field->id] = array('width' => $fieldSettings['width']); } if (isset($fieldSettings['typesettings'])) { $field->settings = $fieldSettings['typesettings']; } $fields[] = $field; } } $blockType->setFields($fields); $blockTypes[] = $blockType; } } $superTableSettings->setBlockTypes($blockTypes); // Save additional field column data - but in the SuperTable field $superTableSettings->columns = $columns; if (!empty($settings['fieldLayout'])) { $superTableSettings->fieldLayout = $settings['fieldLayout']; } if (!empty($settings['staticField'])) { $superTableSettings->staticField = $settings['staticField']; } if (!empty($settings['selectionLabel'])) { $superTableSettings->selectionLabel = $settings['selectionLabel']; } if (!empty($settings['maxRows'])) { $superTableSettings->maxRows = $settings['maxRows']; } return $superTableSettings; }
public function validateFieldSettings(SuperTable_SettingsModel $settings) { $validates = true; $this->_uniqueBlockTypeAndFieldHandles = array(); $uniqueAttributes = array('name', 'handle'); $uniqueAttributeValues = array(); foreach ($settings->getBlockTypes() as $blockType) { if (!$this->validateBlockType($blockType, false)) { // Don't break out of the loop because we still want to get validation errors for the remaining block // types. $validates = false; } } return $validates; }
public function validateFieldSettings(SuperTable_SettingsModel $settings) { $validates = true; foreach ($settings->getBlockTypes() as $btIndex => $blockType) { if (!$this->validateBlockType($blockType, false)) { // Don't break out of the loop because we still want to get validation errors for the remaining block // types. $validates = false; } if ($blockType->hasFieldErrors) { $settings->addErrors($blockType->getErrors()); } } return $validates; }