| @@ 75-102 (lines=28) @@ | ||
| 72 | * @throws \Ffcms\Core\Exception\SyntaxException |
|
| 73 | * @throws \Ffcms\Core\Exception\NativeException |
|
| 74 | */ |
|
| 75 | public function actionUpdate($id) |
|
| 76 | { |
|
| 77 | // get item with trashed objects |
|
| 78 | $record = ContentEntity::withTrashed()->find($id); |
|
| 79 | $isNew = $record->id === null; |
|
| 80 | ||
| 81 | // create empty object if its new |
|
| 82 | if ($isNew === true) { |
|
| 83 | $record = new ContentEntity(); |
|
| 84 | } |
|
| 85 | ||
| 86 | // init model |
|
| 87 | $model = new FormContentUpdate($record); |
|
| 88 | ||
| 89 | // check if model is submit |
|
| 90 | if ($model->send() && $model->validate()) { |
|
| 91 | $model->save(); |
|
| 92 | if ($isNew === true) { |
|
| 93 | App::$Response->redirect('content/index'); |
|
| 94 | } |
|
| 95 | App::$Session->getFlashBag()->add('success', __('Content is successful updated')); |
|
| 96 | } |
|
| 97 | ||
| 98 | // draw response |
|
| 99 | $this->response = App::$View->render('content_update', [ |
|
| 100 | 'model' => $model |
|
| 101 | ]); |
|
| 102 | } |
|
| 103 | ||
| 104 | /** |
|
| 105 | * Delete content by id |
|
| @@ 109-131 (lines=23) @@ | ||
| 106 | * Add and edit additional fields data |
|
| 107 | * @param $id |
|
| 108 | */ |
|
| 109 | public function actionFieldupdate($id) |
|
| 110 | { |
|
| 111 | // get current record or new and init form DI |
|
| 112 | $record = ProfileField::findOrNew($id); |
|
| 113 | $model = new FormFieldUpdate($record); |
|
| 114 | ||
| 115 | $isNew = false; |
|
| 116 | if ($record->id === null) { |
|
| 117 | $isNew = true; |
|
| 118 | } |
|
| 119 | // check if form is submited |
|
| 120 | if ($model->send() && $model->validate()) { |
|
| 121 | $model->save(); |
|
| 122 | if (true === $isNew) { |
|
| 123 | App::$Response->redirect('profile/fieldlist'); |
|
| 124 | } |
|
| 125 | App::$Session->getFlashBag()->add('success', __('Profile field was successful updated')); |
|
| 126 | } |
|
| 127 | ||
| 128 | $this->response = App::$View->render('field_update', [ |
|
| 129 | 'model' => $model->export() |
|
| 130 | ]); |
|
| 131 | } |
|
| 132 | ||
| 133 | /** |
|
| 134 | * Delete custom field action |
|