private function addFormItemFromSchema(FormHelper $form, $columnId, array $columnOptions) { $type = empty($columnOptions['type']) ? 'string' : $columnOptions['type']; $config = ['label' => $columnOptions['label']]; switch ($type) { case 'text': case 'string': $item = new TextFormItem($form, $columnId, $config); break; case 'number': $item = new NumberFormItem($form, $columnId, $config); break; case 'datetime': $item = new DateTimeFormItem($form, $columnId, $config); break; default: throw new \Exception("The Column Type [{$type}] is not valid."); } $form->addItem($item); }
public function handle_set_form_values() { $form = new FormHelper(array(), $this->dataProvider->getEditFormConfig()); $url = new UrlHelper(); // let's not worry about validation right now. $values = json_decode($url->get("values_json", "{}"), true); if ($form->validate($values)) { $this->dataProvider->setRow($url->get("item_id", null), $values); FlashBag::add("alert", "Item has been updated", "success"); return array('type' => 'json', 'data' => array('success' => true)); } else { // TODO show errors on validation fail throw new \Exception("Cannot validate values"); } }