1
|
|
|
<?php |
2
|
|
|
namespace Uccello\Core\Http\Controllers\Core; |
3
|
|
|
|
4
|
|
|
use Kris\LaravelFormBuilder\FormBuilder; |
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use Uccello\Core\Forms\PopupEditForm; |
7
|
|
|
use Uccello\Core\Events\BeforeSaveEvent; |
8
|
|
|
use Uccello\Core\Events\AfterSaveEvent; |
9
|
|
|
use Uccello\Core\Models\Domain; |
10
|
|
|
use Uccello\Core\Models\Module; |
11
|
|
|
use Uccello\Core\Models\Relatedlist; |
12
|
|
|
|
13
|
|
|
class PopupEditController extends Controller |
14
|
|
|
{ |
15
|
|
|
protected $viewName = 'edit.popup'; |
16
|
|
|
protected $formBuilder; |
17
|
|
|
/** |
18
|
|
|
* Check user permissions |
19
|
|
|
*/ |
20
|
|
|
protected function checkPermissions() |
21
|
|
|
{ |
22
|
|
|
$this->middleware('uccello.permissions:create'); |
23
|
|
|
} |
24
|
|
|
public function __construct(FormBuilder $formBuilder) |
25
|
|
|
{ |
26
|
|
|
$this->formBuilder = $formBuilder; |
27
|
|
|
parent::__construct(); |
28
|
|
|
} |
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
public function process(?Domain $domain, Module $module, Request $request) |
33
|
|
|
{ |
34
|
|
|
// Pre-process |
35
|
|
|
$this->preProcess($domain, $module, $request); |
36
|
|
|
// Retrieve record or get a new empty instance |
37
|
|
|
$record = $this->getRecordFromRequest(); |
38
|
|
|
// Get form |
39
|
|
|
$form = $this->getForm($domain, $module, $request); |
40
|
|
|
// Get mode |
41
|
|
|
$mode = 'create'; |
42
|
|
|
return $this->autoView([ |
43
|
|
|
'form' => $form, |
44
|
|
|
'record' => $record, |
45
|
|
|
'mode' => $mode |
46
|
|
|
]); |
47
|
|
|
} |
48
|
|
|
/** |
49
|
|
|
* Create or update record into database |
50
|
|
|
* |
51
|
|
|
* @param Domain|null $domain |
52
|
|
|
* @param Module $module |
53
|
|
|
* @param boolean $redirect |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
|
|
public function save(?Domain $domain, Module $module, Request $request, bool $redirect = false) |
57
|
|
|
{ |
58
|
|
|
// Pre-process |
59
|
|
|
$this->preProcess($domain, $module, $request); |
60
|
|
|
// Retrieve record or get a new empty instance |
61
|
|
|
$record = $this->getRecordFromRequest(); |
62
|
|
|
// Get form |
63
|
|
|
$form = $this->getForm($domain, $module, $request, $record); |
64
|
|
|
$values = $form->getFieldValues(); |
65
|
|
|
$record = $form->getModel(); |
66
|
|
|
$request = $form->getRequest(); |
67
|
|
|
//Add fields value to record |
68
|
|
|
foreach ($values as $fieldName => $value) { |
69
|
|
|
$field = $module->getField($fieldName); |
70
|
|
|
// If the field exists format the value and store it in the good model column |
71
|
|
|
if (!is_null($field)) { |
72
|
|
|
$column = $field->column; |
73
|
|
|
$form->getModel()->$column = uitype($field->uitype_id)->getFormattedValueToSave($request, $field, $value, $record, $domain, $module); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
// Redirect if form not valid |
77
|
|
|
if (! $form->isValid()) { |
78
|
|
|
ucnotify(uctrans('notification.form.not_valid', $module), 'error'); |
79
|
|
|
$response = redirect(route('uccello.popup.edit', ['domain' => $domain->slug, 'module' => $module->name])); |
|
|
|
|
80
|
|
|
$response = $response->withErrors($form->getErrors(), $form->getErrorBag())->withInput(); |
81
|
|
|
return $response; |
|
|
|
|
82
|
|
|
} |
83
|
|
|
event(new BeforeSaveEvent($domain, $module, $request, $record, 'create')); |
84
|
|
|
// Save record |
85
|
|
|
$record->save(); |
86
|
|
|
event(new AfterSaveEvent($domain, $module, $request, $record, 'create')); |
87
|
|
|
return $record; |
88
|
|
|
} |
89
|
|
|
public function getForm($domain, $module, $request, $record = null) |
90
|
|
|
{ |
91
|
|
|
if ($record === null) { |
92
|
|
|
$modelClass = $module->model_class; |
93
|
|
|
$record = new $modelClass; |
94
|
|
|
} |
95
|
|
|
return $this->formBuilder->create(PopupEditForm::class, [ |
96
|
|
|
'model' => $record, |
97
|
|
|
'data' => [ |
98
|
|
|
'domain' => $domain, |
99
|
|
|
'module' => $module, |
100
|
|
|
'request' => $request |
101
|
|
|
] |
102
|
|
|
]); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths