Example #1
0
 /**
  * New field page.
  */
 public function action_new()
 {
     // Create field
     $field = new CustomField(array('type' => 'text', 'regex' => '^(.*)$'));
     // Check if the form has been submitted
     if (Request::method() == 'post') {
         $data = array();
         // Loop over properties
         foreach (CustomField::properties() as $property) {
             // Check if it's set and not empty
             if (isset(Request::$post[$property])) {
                 $data[$property] = Request::$post[$property];
             }
         }
         // Is required?
         if (!isset(Request::$post['is_required'])) {
             $data['is_required'] = 0;
         }
         // Project ID
         $data['project_id'] = $this->project->id;
         // Set field properties
         $field->set($data);
         // Save and redirect
         if ($field->save()) {
             if ($this->is_api) {
                 return \API::response(1, array('field' => $field));
             } else {
                 Request::redirectTo($this->project->href('settings/custom_fields'));
             }
         }
     }
     // Send field object to view
     View::set(compact('field'));
 }
Example #2
0
 /**
  * Create custom field.
  */
 public function createAction()
 {
     $field = new CustomField($this->fieldParams());
     return $this->respondTo(function ($format) use($field) {
         if ($field->save()) {
             if ($format === 'html') {
                 return $this->redirectTo('project_settings_custom_fields');
             } elseif ($format === 'json') {
                 return $this->jsonResponse($field);
             }
         } else {
             if ($format === 'html') {
                 return $this->render('project_settings/custom_fields/new.phtml', ['field' => $field]);
             } elseif ($format === 'json') {
                 return $this->jsonResponse(['errors' => $field->errors(), 'field' => $field], 422);
             }
         }
     });
 }
Example #3
0
function createCustomField($project = null)
{
    if (!$project) {
        $project = createProject();
    }
    $hash = mkRandomHash(5);
    $customField = new CustomField(['name' => $hash . '-name', 'slug' => $hash . '-slug', 'type' => 1, 'ticket_type_ids' => 0, 'project_id' => $project['id']]);
    $customField->save();
    return $customField;
}