uccellolabs /
uccello
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Uccello\Core\Forms; |
||
| 4 | |||
| 5 | class PopupEditForm extends EditForm |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Build the form. |
||
| 9 | * |
||
| 10 | * @return void |
||
| 11 | */ |
||
| 12 | public function buildForm() |
||
| 13 | { |
||
| 14 | // Get domain data |
||
| 15 | $domain = $this->getData('domain'); |
||
| 16 | // Get module data |
||
| 17 | $module = $this->getData('module'); |
||
| 18 | // Get request data |
||
| 19 | $request = $this->getData('request'); |
||
| 20 | $fieldName = $request->get('field'); |
||
| 21 | // Make route params |
||
| 22 | $routeParams = [ ]; |
||
| 23 | // Get mode |
||
| 24 | $mode = 'create'; |
||
| 25 | // Options |
||
| 26 | $this->formOptions = [ |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 27 | 'method' => 'POST', // Use POST method |
||
| 28 | 'url' => ucroute('uccello.popup.save', $domain, $module, $routeParams), // URL to call |
||
| 29 | 'class' => 'edit-form', |
||
| 30 | 'novalidate', // Deactivate HTML5 validation |
||
| 31 | 'id' => 'form_popup_'.$fieldName |
||
| 32 | ]; |
||
| 33 | // Add all fields |
||
| 34 | foreach ($module->fields as $field) { |
||
| 35 | // Check if the field can be displayed |
||
| 36 | if (($mode === 'edit' && !$field->isEditable()) || ($mode === 'create' && !$field->isCreateable())) { |
||
| 37 | continue; |
||
| 38 | } |
||
| 39 | // Get field type: if the field must be repeated, the type is "repeated" else get the FormBuilder type |
||
| 40 | $fieldType = isset($field->data->repeated) |
||
| 41 | && $field->data->repeated === true ? 'repeated' : $this->getFormBuilderType($field); |
||
| 42 | // Get field options |
||
| 43 | $fieldOptions = $this->getFieldOptions($field); |
||
| 44 | // Add field to form |
||
| 45 | $this->add($field->name, $fieldType, $fieldOptions); |
||
| 46 | } |
||
| 47 | // Add a save button |
||
| 48 | $this->add('save_btn', 'submit', [ |
||
| 49 | 'label' => '<i class="material-icons left">save</i> '.uctrans('button.save', $module), |
||
| 50 | 'attr' => [ |
||
| 51 | 'class' => 'btn waves-effect green right', |
||
| 52 | ] |
||
| 53 | ]); |
||
| 54 | } |
||
| 55 | } |
||
| 56 |