'staff_2', 'requestData' => [ 'name' => [ 'validation' => DataValidator::length(2, 100), 'error' => ERRORS::INVALID_NAME ], 'type' => [ 'validation' => DataValidator::oneOf( DataValidator::equals('text'), DataValidator::equals('select') ), 'error' => ERRORS::INVALID_CUSTOM_FIELD_TYPE ], 'options' => [ 'validation' => DataValidator::oneOf( DataValidator::json(), DataValidator::nullType() ), 'error' => ERRORS::INVALID_CUSTOM_FIELD_OPTIONS ] ] ]; } public function handler() { $name = Controller::request('name'); $type = Controller::request('type'); $description = Controller::request('description'); $options = Controller::request('options'); if(!Customfield::getDataStore($name, 'name')->isNull()) throw new Exception(ERRORS::CUSTOM_FIELD_ALREADY_EXISTS); $customField = new Customfield(); $customField->setProperties([ 'name' => $name, 'type' => $type, 'description' => $description, 'ownCustomfieldoptionList' => $this->getOptionList($options) ]); $customField->store(); Response::respondSuccess(); } public function getOptionList($optionNames) { $options = new DataStoreList(); if(!$optionNames) return $options; $optionNames = json_decode($optionNames); foreach($optionNames as $optionName) { $option = new Customfieldoption(); $option->setProperties([ 'name' => $optionName, ]); $options->add($option); } return $options; } }