/** * @Route("/", methods="POST") * @Route("/{id}", methods="POST", requirements={"id"="\d+"}) * @Request({"field": "array", "id": "int"}, csrf=true) */ public function saveAction($data, $id = 0) { if (!($field = Field::find($id))) { $field = Field::create(); unset($data['id']); } try { $field->save($data); } catch (Exception $e) { App::abort(400, $e->getMessage()); } return ['message' => 'success', 'field' => $field]; }
/** * @Route("/", methods="POST") * @Route("/{id}", methods="POST", requirements={"id"="\d+"}) * @Request({"field": "array", "id": "int"}, csrf=true) */ public function saveAction($data, $id = 0) { if (!($field = Field::find($id))) { $field = Field::create(['data' => ['value' => [], 'data' => [], 'classSfx' => '', 'help_text' => '', 'help_show' => '']]); unset($data['id']); } if (!($data['slug'] = App::filter($data['slug'] ?: $data['label'], 'slugify'))) { App::abort(400, __('Invalid slug.')); } try { $field->save($data); } catch (Exception $e) { App::abort(400, $e->getMessage()); } return ['message' => 'success', 'field' => $field]; }
/** * @Route("/edit") * @Request({"id"}) * @Access("site: manage site", admin=true) */ public function editAction($id = '') { $userprofile = App::module('bixie/userprofile'); if (is_numeric($id)) { $field = Field::find($id); } else { $field = Field::create(); $field->setType($id); } if (!$field) { throw new NotFoundException(__('Field not found.')); } if (!($type = $userprofile->getType($field->type))) { throw new NotFoundException(__('Type not found.')); } return ['$view' => ['title' => __('Field'), 'name' => 'bixie/userprofile/admin/edit.php'], '$data' => ['field' => $field, 'type' => $type, 'roles' => array_values(Role::findAll())]]; }
/** * @Route("/edit") * @Request({"id"}) * @Access("site: manage site", admin=true) */ public function editAction($id = '') { /** @var \Bixie\Userprofile\UserprofileModule $userprofile */ $userprofile = App::module('bixie/userprofile'); if (is_numeric($id)) { $field = Field::find($id); } else { $field = Field::create(); $field->setFieldType($id); $field->set('value', []); $field->set('data', []); } if (!$field) { throw new NotFoundException(__('Field not found.')); } if (!($type = $userprofile->getFieldType($field->type))) { throw new NotFoundException(__('Type not found.')); } $fixedFields = ['multiple', 'required', 'controls', 'repeatable']; if (!$field->id) { foreach ($type->getConfig() as $key => $value) { if (!in_array($key, $fixedFields)) { $field->set($key, $value); } } } //check fixed value foreach ($fixedFields as $key) { if (!isset($type[$key])) { $type[$key] = 0; } if ($type[$key] != -1) { $field->set($key, $type[$key]); } } return ['$view' => ['title' => __('Field'), 'name' => 'bixie/userprofile/admin/edit.php'], '$data' => ['field' => $field, 'type' => $type, 'roles' => array_values(Role::findAll())]]; }