Total Complexity | 87 |
Total Lines | 890 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like FormbuilderCrudController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FormbuilderCrudController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | class FormbuilderCrudController extends CrudController |
||
26 | { |
||
27 | use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation; |
||
28 | use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation { |
||
29 | store as traitStore; |
||
30 | } |
||
31 | use \Backpack\CRUD\app\Http\Controllers\Operations\InlineCreateOperation; |
||
32 | use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation { |
||
33 | update as traitUpdate; |
||
34 | } |
||
35 | use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation { |
||
36 | destroy as traitDestroy; |
||
37 | } |
||
38 | use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation; |
||
39 | use Field; |
||
40 | use CrudPermissions; |
||
41 | |||
42 | |||
43 | public function setup() |
||
44 | { |
||
45 | CRUD::setModel(Formbuilder::class); |
||
46 | CRUD::setRoute(config('backpack.base.route_prefix') . '/formbuilder'); |
||
47 | CRUD::setEntityNameStrings( |
||
48 | __('medianet-dev.backpack-form::formbuilder.labels.entity_form'), |
||
49 | __('medianet-dev.backpack-form::formbuilder.labels.entities_form') |
||
50 | ); |
||
51 | $this->crud->addButtonFromModelFunction('line', 'entries_list', 'entriesList', 'beginning'); |
||
52 | } |
||
53 | |||
54 | protected function setupListOperation() |
||
55 | { |
||
56 | $this->crud->addColumns([ |
||
57 | [ |
||
58 | 'name' => 'uniq_id', |
||
59 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.uuid')), |
||
60 | 'type' => 'text', |
||
61 | ], |
||
62 | [ |
||
63 | 'name' => 'translation.title', |
||
64 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.title')), |
||
65 | 'type' => 'text', |
||
66 | ], |
||
67 | [ |
||
68 | 'name' => 'translation.header', |
||
69 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.header')), |
||
70 | 'type' => 'text', |
||
71 | ], |
||
72 | [ |
||
73 | 'name' => 'translation.footer', |
||
74 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.footer')), |
||
75 | 'type' => 'text', |
||
76 | ], |
||
77 | [ |
||
78 | 'name' => 'in_database', |
||
79 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.in_database')), |
||
80 | 'type' => 'boolean', // Changed from 'check' to 'boolean' for better clarity |
||
81 | ], |
||
82 | [ |
||
83 | 'name' => 'by_mail', |
||
84 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.by_mail')), |
||
85 | 'type' => 'boolean', // Changed from 'check' to 'boolean' for better clarity |
||
86 | ], |
||
87 | [ |
||
88 | 'name' => 'updated_at', |
||
89 | 'type' => 'datetime', |
||
90 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.updated_at')) |
||
91 | ], |
||
92 | [ |
||
93 | 'name' => 'created_at', |
||
94 | 'type' => 'datetime', |
||
95 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.created_at')) |
||
96 | ] |
||
97 | ]); |
||
98 | } |
||
99 | |||
100 | protected function setupShowOperation() |
||
101 | { |
||
102 | $this->crud->set('show.setFromDb', false); |
||
103 | $this->crud->addColumns([ |
||
104 | [ |
||
105 | 'name' => 'uniq_id', |
||
106 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.uuid')), |
||
107 | 'type' => 'text', |
||
108 | ], |
||
109 | [ |
||
110 | 'name' => 'translation.title', |
||
111 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.title')), |
||
112 | 'type' => 'text', |
||
113 | ], |
||
114 | [ |
||
115 | 'name' => 'translation.description', |
||
116 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.description')), |
||
117 | 'type' => 'html', |
||
118 | ], |
||
119 | [ |
||
120 | 'name' => 'translation.slug', |
||
121 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.slug')), |
||
122 | 'type' => 'text', |
||
123 | ], |
||
124 | [ |
||
125 | 'name' => 'translation.header', |
||
126 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.header')), |
||
127 | 'type' => 'text', |
||
128 | ], |
||
129 | [ |
||
130 | 'name' => 'translation.footer', |
||
131 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.footer')), |
||
132 | 'type' => 'text', |
||
133 | ], |
||
134 | [ |
||
135 | 'name' => 'text_button', |
||
136 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.text_button')), |
||
137 | 'type' => 'text', |
||
138 | ], |
||
139 | [ |
||
140 | 'name' => 'in_database', |
||
141 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.in_database')), |
||
142 | 'type' => 'boolean', |
||
143 | ], |
||
144 | [ |
||
145 | 'name' => 'display_title', |
||
146 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.display_title')), |
||
147 | 'type' => 'boolean', |
||
148 | ], |
||
149 | [ |
||
150 | 'name' => 'multiple_steps', |
||
151 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.multiple_steps')), |
||
152 | 'type' => 'boolean', |
||
153 | ], |
||
154 | [ |
||
155 | 'name' => 'display_header', |
||
156 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.display_header')), |
||
157 | 'type' => 'boolean', |
||
158 | ], |
||
159 | [ |
||
160 | 'name' => 'display_footer', |
||
161 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.display_footer')), |
||
162 | 'type' => 'boolean', |
||
163 | ], |
||
164 | [ |
||
165 | 'name' => 'display_intro', |
||
166 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.display_intro')), |
||
167 | 'type' => 'boolean', |
||
168 | ], |
||
169 | [ |
||
170 | 'name' => 'display_captcha', |
||
171 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.display_captcha')), |
||
172 | 'type' => 'boolean', |
||
173 | ], |
||
174 | [ |
||
175 | 'name' => 'by_mail', |
||
176 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.by_mail')), |
||
177 | 'type' => 'boolean', |
||
178 | ], |
||
179 | [ |
||
180 | 'name' => 'mail_to', |
||
181 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.mail_to')), |
||
182 | 'type' => 'text', |
||
183 | ], |
||
184 | [ |
||
185 | 'name' => 'include_data', |
||
186 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.include_data')), |
||
187 | 'type' => 'boolean', |
||
188 | ], |
||
189 | [ |
||
190 | 'name' => 'subject_admin', |
||
191 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.subject_admin')), |
||
192 | 'type' => 'text', |
||
193 | ], |
||
194 | [ |
||
195 | 'name' => 'message_admin', |
||
196 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.message_admin')), |
||
197 | 'type' => 'html', |
||
198 | ], |
||
199 | [ |
||
200 | 'name' => 'copy_user', |
||
201 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.copy_user')), |
||
202 | 'type' => 'boolean', |
||
203 | ], |
||
204 | [ |
||
205 | 'name' => 'field_mail_name', |
||
206 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.field_mail_name')), |
||
207 | 'type' => 'text', |
||
208 | ], |
||
209 | [ |
||
210 | 'name' => 'subject_user', |
||
211 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.subject_user')), |
||
212 | 'type' => 'text', |
||
213 | ], |
||
214 | [ |
||
215 | 'name' => 'message_user', |
||
216 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.message_user')), |
||
217 | 'type' => 'html', |
||
218 | ], |
||
219 | [ |
||
220 | 'name' => 'form', |
||
221 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.form')), |
||
222 | 'type' => 'form_builder_preview', |
||
223 | 'view_namespace' => 'medianet.backpack-form::columns', |
||
224 | ], |
||
225 | [ |
||
226 | 'name' => 'created_at', |
||
227 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.created_at')), |
||
228 | 'type' => 'datetime', |
||
229 | ], |
||
230 | [ |
||
231 | 'name' => 'updated_at', |
||
232 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.updated_at')), |
||
233 | 'type' => 'datetime', |
||
234 | ], |
||
235 | ]); |
||
236 | } |
||
237 | |||
238 | protected function setupCreateOperation() |
||
239 | { |
||
240 | |||
241 | CRUD::setValidation(FormbuilderRequest::class); |
||
242 | |||
243 | $translations = $this->getTranslations( |
||
244 | $this->crud->getOperation(), |
||
245 | $this->crud->getModel(), |
||
246 | $this->crud->getCurrentEntry() |
||
247 | ); |
||
248 | $languages = languages(); |
||
249 | |||
250 | // Language-specific fields |
||
251 | foreach ($languages as $key => $value) { |
||
252 | $this->crud->addFields([ |
||
253 | [ |
||
254 | 'name' => "{$key}[title]", |
||
255 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.title')), |
||
256 | 'type' => 'text', |
||
257 | 'default' => ($translations && isset($translations->translations[$key])) |
||
258 | ? $translations->translations[$key]->title |
||
259 | : '', |
||
260 | 'tab' => __($value), |
||
261 | 'slug_class' => "slug_{$key}" |
||
262 | ], |
||
263 | [ |
||
264 | 'name' => "{$key}[slug]", |
||
265 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.slug')), |
||
266 | 'type' => 'text', |
||
267 | 'slug' => true, |
||
268 | 'default' => ($translations && isset($translations->translations[$key])) |
||
269 | ? $translations->translations[$key]->slug ?? null |
||
270 | : '', |
||
271 | 'tab' => __($value), |
||
272 | 'attributes' => ['class' => "slug_{$key} form-control"] |
||
273 | ], |
||
274 | [ |
||
275 | 'name' => "{$key}[description]", |
||
276 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.description')), |
||
277 | 'type' => 'tinymce', |
||
278 | 'default' => ($translations && isset($translations->translations[$key])) |
||
279 | ? $translations->translations[$key]->description |
||
280 | : '', |
||
281 | 'tab' => __($value), |
||
282 | 'options' => $this->tinyMceOption() |
||
283 | ], |
||
284 | [ |
||
285 | 'name' => "{$key}[text_button]", |
||
286 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.text_button')), |
||
287 | 'type' => 'text', |
||
288 | 'default' => __('medianet-dev.backpack-form::formbuilder.labels.default_text_button'), |
||
289 | 'tab' => __($value) |
||
290 | ], |
||
291 | [ |
||
292 | 'name' => "{$key}[header]", |
||
293 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.header')), |
||
294 | 'type' => 'tinymce', |
||
295 | 'options' => $this->tinyMceOption(), |
||
296 | 'default' => ($translations && isset($translations->translations[$key])) |
||
297 | ? $translations->translations[$key]->header |
||
298 | : '', |
||
299 | 'tab' => __($value) |
||
300 | ], |
||
301 | [ |
||
302 | 'name' => "{$key}[footer]", |
||
303 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.footer')), |
||
304 | 'type' => 'tinymce', |
||
305 | 'options' => $this->tinyMceOption(), |
||
306 | 'default' => ($translations && isset($translations->translations[$key])) |
||
307 | ? $translations->translations[$key]->footer |
||
308 | : '', |
||
309 | 'tab' => __($value) |
||
310 | ] |
||
311 | ]); |
||
312 | } |
||
313 | // Create an instance of FormStepCrudController |
||
314 | |||
315 | // $crud = new FormStepCrudController(); |
||
316 | // $dataCrud = $crud->getCrudData(); |
||
317 | |||
318 | // Call the setupListOperation method |
||
319 | |||
320 | // Main form fields |
||
321 | $this->crud->addFields([ |
||
322 | // Form.io Component Builder (JSON) |
||
323 | [ |
||
324 | 'name' => 'formio_builder', |
||
325 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.formio_builder')), |
||
326 | 'type' => 'form_builder_custom_html', |
||
327 | 'value' => '<div id="formio-builder-container" class="mb-4"> <div id="formio-builder"></div></div>', |
||
328 | 'tab' => __('medianet-dev.backpack-form::formbuilder.tabs.form_io_builder') |
||
329 | ], |
||
330 | |||
331 | // Hidden field to store Form.io component JSON |
||
332 | [ |
||
333 | 'name' => 'formio_component', |
||
334 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.formio_component')), |
||
335 | 'type' => 'hidden', |
||
336 | 'attributes' => ['id' => 'formio-component-json'], |
||
337 | 'tab' => __('medianet-dev.backpack-form::formbuilder.tabs.form_io_builder') |
||
338 | ], |
||
339 | |||
340 | // Validation rules (JSON) |
||
341 | [ |
||
342 | 'name' => 'validation_rules', |
||
343 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.validation_rules')), |
||
344 | 'type' => 'textarea', |
||
345 | 'attributes' => ['rows' => 5, 'id' => 'validation-rules-json'], |
||
346 | 'tab' => __('medianet-dev.backpack-form::formbuilder.tabs.validation'), |
||
347 | 'hint' => 'Enter validation rules in JSON format' |
||
348 | ], |
||
349 | |||
350 | // Config tab fields |
||
351 | |||
352 | [ |
||
353 | 'name' => 'in_database', |
||
354 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.in_database')), |
||
355 | 'type' => 'select_from_array', |
||
356 | 'options' => __('medianet-dev.backpack-form::formbuilder.labels.bool'), |
||
357 | 'wrapper' => ['class' => 'form-group col-md-6'], |
||
358 | 'tab' => __('medianet-dev.backpack-form::formbuilder.labels.config_tab') |
||
359 | ], |
||
360 | [ |
||
361 | 'name' => 'display_title', |
||
362 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.display_title')), |
||
363 | 'type' => 'select_from_array', |
||
364 | 'options' => __('medianet-dev.backpack-form::formbuilder.labels.bool'), |
||
365 | 'wrapper' => ['class' => 'form-group col-md-6'], |
||
366 | 'default' => 1, |
||
367 | 'tab' => __('medianet-dev.backpack-form::formbuilder.labels.config_tab') |
||
368 | ], |
||
369 | [ |
||
370 | 'name' => 'display_intro', |
||
371 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.display_intro')), |
||
372 | 'type' => 'select_from_array', |
||
373 | 'options' => __('medianet-dev.backpack-form::formbuilder.labels.bool'), |
||
374 | 'wrapper' => ['class' => 'form-group col-md-6'], |
||
375 | 'default' => 1, |
||
376 | 'tab' => __('medianet-dev.backpack-form::formbuilder.labels.config_tab') |
||
377 | ], |
||
378 | [ |
||
379 | 'name' => 'display_captcha', |
||
380 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.display_captcha')), |
||
381 | 'type' => 'select_from_array', |
||
382 | 'options' => __('medianet-dev.backpack-form::formbuilder.labels.bool'), |
||
383 | 'wrapper' => ['class' => 'form-group col-md-6'], |
||
384 | 'default' => 1, |
||
385 | 'tab' => __('medianet-dev.backpack-form::formbuilder.labels.config_tab') |
||
386 | ], |
||
387 | [ |
||
388 | 'name' => 'display_title', |
||
389 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.display_title')), |
||
390 | 'type' => 'select_from_array', |
||
391 | 'options' => __('medianet-dev.backpack-form::formbuilder.labels.bool'), |
||
392 | 'wrapper' => ['class' => 'form-group col-md-6'], |
||
393 | 'default' => 1, |
||
394 | 'tab' => __('medianet-dev.backpack-form::formbuilder.labels.config_tab') |
||
395 | ], |
||
396 | [ |
||
397 | 'name' => 'display_header', |
||
398 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.display_header')), |
||
399 | 'type' => 'select_from_array', |
||
400 | 'options' => __('medianet-dev.backpack-form::formbuilder.labels.bool'), |
||
401 | 'wrapper' => ['class' => 'form-group col-md-6'], |
||
402 | 'default' => 1, |
||
403 | 'tab' => __('medianet-dev.backpack-form::formbuilder.labels.config_tab') |
||
404 | ], |
||
405 | |||
406 | [ |
||
407 | 'name' => 'display_footer', |
||
408 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.display_footer')), |
||
409 | 'type' => 'select_from_array', |
||
410 | 'options' => __('medianet-dev.backpack-form::formbuilder.labels.bool'), |
||
411 | 'wrapper' => ['class' => 'form-group col-md-6'], |
||
412 | 'default' => 1, |
||
413 | 'tab' => __('medianet-dev.backpack-form::formbuilder.labels.config_tab') |
||
414 | ], |
||
415 | [ |
||
416 | 'name' => 'multiple_steps', |
||
417 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.multiple_steps')), |
||
418 | 'type' => 'select_from_array', |
||
419 | 'options' => __('medianet-dev.backpack-form::formbuilder.labels.bool'), |
||
420 | 'wrapper' => ['class' => 'form-group col-md-6'], |
||
421 | 'default' => 1, |
||
422 | 'tab' => __('medianet-dev.backpack-form::formbuilder.labels.config_tab') |
||
423 | ], |
||
424 | |||
425 | // Notifications tab fields |
||
426 | [ |
||
427 | 'name' => 'separator_email_admin', |
||
428 | 'type' => 'custom_html', |
||
429 | 'value' => __('medianet-dev.backpack-form::formbuilder.labels.notification_admin'), |
||
430 | 'tab' => __('medianet-dev.backpack-form::formbuilder.labels.notifications_tab') |
||
431 | ], |
||
432 | [ |
||
433 | 'name' => 'by_mail', |
||
434 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.by_mail')), |
||
435 | 'type' => 'select_from_array', |
||
436 | 'options' => __('medianet-dev.backpack-form::formbuilder.labels.bool'), |
||
437 | 'wrapper' => ['class' => 'form-group col-md-6'], |
||
438 | 'tab' => __('medianet-dev.backpack-form::formbuilder.labels.notifications_tab') |
||
439 | ], |
||
440 | [ |
||
441 | 'name' => 'mail_to', |
||
442 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.mail_to')), |
||
443 | 'hint' => ucfirst(__('medianet-dev.backpack-form::formbuilder.hints.mail_to')), |
||
444 | 'type' => 'text', |
||
445 | 'wrapper' => ['class' => 'form-group col-md-6'], |
||
446 | 'attributes' => ['placeholder' => config('backpack-form.email.to')], |
||
447 | 'tab' => __('medianet-dev.backpack-form::formbuilder.labels.notifications_tab') |
||
448 | ], |
||
449 | [ |
||
450 | 'name' => 'include_data', |
||
451 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.include_data')), |
||
452 | 'hint' => ucfirst(__('medianet-dev.backpack-form::formbuilder.hints.include_data')), |
||
453 | 'type' => 'select_from_array', |
||
454 | 'options' => __('medianet-dev.backpack-form::formbuilder.labels.bool'), |
||
455 | 'wrapper' => ['class' => 'form-group col-md-6'], |
||
456 | 'tab' => __('medianet-dev.backpack-form::formbuilder.labels.notifications_tab') |
||
457 | ], |
||
458 | [ |
||
459 | 'name' => 'subject_admin', |
||
460 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.subject_admin')), |
||
461 | 'type' => 'text', |
||
462 | 'wrapper' => ['class' => 'form-group col-md-6'], |
||
463 | 'attributes' => [ |
||
464 | 'placeholder' => __('medianet-dev.backpack-form::formbuilder.emails.default_subject', [ |
||
465 | 'app_name' => config('app.name') |
||
466 | ]) |
||
467 | ], |
||
468 | 'tab' => __('medianet-dev.backpack-form::formbuilder.labels.notifications_tab') |
||
469 | ], |
||
470 | [ |
||
471 | 'name' => 'message_admin', |
||
472 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.message_admin')), |
||
473 | 'hint' => ucfirst(__('medianet-dev.backpack-form::formbuilder.hints.message_admin')), |
||
474 | 'type' => 'summernote', |
||
475 | 'options' => [ |
||
476 | 'toolbar' => [ |
||
477 | ['style', ['bold', 'italic', 'underline', 'clear']], |
||
478 | ['insert', ['link', 'hr']], |
||
479 | ['fontsize', ['fontsize']], |
||
480 | ['color', ['color']], |
||
481 | ['para', ['ul', 'ol', 'paragraph']], |
||
482 | ['height', ['height']] |
||
483 | ], |
||
484 | 'placeholder' => __('medianet-dev.backpack-form::formbuilder.emails.message_admin', ['form_title' => '']) |
||
485 | ], |
||
486 | 'tab' => __('medianet-dev.backpack-form::formbuilder.labels.notifications_tab') |
||
487 | ], |
||
488 | [ |
||
489 | 'name' => 'separator_email_user', |
||
490 | 'type' => 'custom_html', |
||
491 | 'value' => __('medianet-dev.backpack-form::formbuilder.labels.notification_user'), |
||
492 | 'tab' => __('medianet-dev.backpack-form::formbuilder.labels.notifications_tab') |
||
493 | ], |
||
494 | [ |
||
495 | 'name' => 'copy_user', |
||
496 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.copy_user')), |
||
497 | 'type' => 'select_from_array', |
||
498 | 'options' => __('medianet-dev.backpack-form::formbuilder.labels.bool'), |
||
499 | 'wrapper' => ['class' => 'form-group col-md-6'], |
||
500 | 'tab' => __('medianet-dev.backpack-form::formbuilder.labels.notifications_tab') |
||
501 | ], |
||
502 | [ |
||
503 | 'name' => 'field_mail_name', |
||
504 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.field_mail_name')), |
||
505 | 'hint' => ucfirst(__('medianet-dev.backpack-form::formbuilder.hints.field_mail_name')), |
||
506 | 'type' => 'text', |
||
507 | 'wrapper' => ['class' => 'form-group col-md-6'], |
||
508 | 'tab' => __('medianet-dev.backpack-form::formbuilder.labels.notifications_tab') |
||
509 | ], |
||
510 | [ |
||
511 | 'name' => 'subject_user', |
||
512 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.subject_user')), |
||
513 | 'type' => 'text', |
||
514 | 'wrapper' => ['class' => 'form-group col-md-6'], |
||
515 | 'attributes' => [ |
||
516 | 'placeholder' => __('medianet-dev.backpack-form::formbuilder.emails.default_subject', [ |
||
517 | 'app_name' => config('app.name') |
||
518 | ]) |
||
519 | ], |
||
520 | 'tab' => __('medianet-dev.backpack-form::formbuilder.labels.notifications_tab') |
||
521 | ], |
||
522 | [ |
||
523 | 'name' => 'message_user', |
||
524 | 'label' => ucfirst(__('medianet-dev.backpack-form::formbuilder.labels.message_user')), |
||
525 | 'hint' => ucfirst(__('medianet-dev.backpack-form::formbuilder.hints.message_user')), |
||
526 | 'type' => 'summernote', |
||
527 | 'options' => [ |
||
528 | 'toolbar' => [ |
||
529 | ['style', ['bold', 'italic', 'underline', 'clear']], |
||
530 | ['insert', ['link', 'hr']], |
||
531 | ['fontsize', ['fontsize']], |
||
532 | ['color', ['color']], |
||
533 | ['para', ['ul', 'ol', 'paragraph']], |
||
534 | ['height', ['height']] |
||
535 | ], |
||
536 | 'placeholder' => __('medianet-dev.backpack-form::formbuilder.emails.message_user', [ |
||
537 | 'app_name' => config('app.name') |
||
538 | ]) |
||
539 | ], |
||
540 | 'tab' => __('medianet-dev.backpack-form::formbuilder.labels.notifications_tab') |
||
541 | ] |
||
542 | ]); |
||
543 | |||
544 | if ( |
||
545 | empty(config('backpack-form.captcha_v3_site_key')) || |
||
546 | empty(config('backpack-form.captcha_v3_secret_key')) |
||
547 | ) { |
||
548 | $this->crud->field('display_captcha') |
||
549 | ->hint(__('medianet-dev.backpack-form::formbuilder.hints.captcha_config_error')) |
||
550 | ->attributes(['disabled' => 'disabled']); |
||
551 | } |
||
552 | |||
553 | //$this->addFormioBuilderScript(); |
||
554 | } |
||
555 | |||
556 | /** |
||
557 | * Add JavaScript for handling the Form.io builder |
||
558 | */ |
||
559 | protected function addFormioBuilderScript() |
||
560 | { |
||
561 | $this->crud->addField([ |
||
562 | 'name' => 'formio_builder_script', |
||
563 | 'type' => 'form_builder_custom_html', |
||
564 | 'tab' => __('medianet-dev.backpack-form::formbuilder.tabs.form_io_builder'), |
||
565 | ]); |
||
566 | } |
||
567 | protected function setupUpdateOperation() |
||
568 | { |
||
569 | $this->setupCreateOperation(); |
||
570 | } |
||
571 | |||
572 | public function store() |
||
573 | { |
||
574 | // \DB::beginTransaction(); |
||
575 | try { |
||
576 | // dd(request()->all()); |
||
577 | $response = $this->traitStore(); |
||
578 | $form = $this->crud->getCurrentEntry(); |
||
579 | setAuditFields($form, 'create'); |
||
580 | |||
581 | if (!$form || !$form->id) { |
||
582 | return back()->withErrors(['message' => __('medianet-dev.backpack-form::formbuilder.validations.form_not_found')]); |
||
583 | } |
||
584 | |||
585 | // Save translations in bulk |
||
586 | $translationsToInsert = []; |
||
587 | $languages = languages(); |
||
588 | foreach ($languages as $locale => $language) { |
||
589 | if (request()->has($locale)) { |
||
590 | $translationData = request()->input($locale); |
||
591 | if (isset($translationData['title']) && !empty($translationData['title'])) { |
||
592 | $translationsToInsert[] = [ |
||
593 | 'title' => $translationData['title'], |
||
594 | 'text_button' => $translationData['text_button'] ?? null, |
||
595 | 'slug' => $translationData['slug'] ?? null, |
||
596 | 'description' => $translationData['description'] ?? null, |
||
597 | 'header' => $translationData['header'] ?? null, |
||
598 | 'footer' => $translationData['footer'] ?? null, |
||
599 | 'form_id' => $form->id, |
||
600 | 'locale' => $locale, |
||
601 | 'created_at' => now(), |
||
602 | 'updated_at' => now(), |
||
603 | ]; |
||
604 | } |
||
605 | } |
||
606 | } |
||
607 | if (!empty($translationsToInsert)) { |
||
608 | FormbuilderTranslation::insert($translationsToInsert); |
||
609 | } |
||
610 | |||
611 | // Update form components if available |
||
612 | if (request()->has('formio_component')) { |
||
613 | $formComponents = json_decode(request()->formio_component); |
||
614 | $form->update(['formio_component' => $formComponents]); |
||
615 | |||
616 | $this->processFormStepsAndFields($form, $formComponents); |
||
617 | } |
||
618 | |||
619 | // \DB::commit(); |
||
620 | return $response; |
||
621 | } catch (\Exception $e) { |
||
622 | \Log::error('Form creation failed: ' . $e->getMessage()); |
||
623 | return back()->withErrors(['message' => __('medianet-dev.backpack-form::formbuilder.validations.form_creation_failed')]); |
||
624 | } |
||
625 | } |
||
626 | |||
627 | public function update() |
||
628 | { |
||
629 | // \DB::beginTransaction(); |
||
630 | try { |
||
631 | $response = $this->traitUpdate(); |
||
632 | $form = $this->crud->getCurrentEntry(); |
||
633 | setAuditFields($form, 'update'); |
||
634 | |||
635 | if (!$form || !$form->id) { |
||
636 | return back()->withErrors(['message' => __('medianet-dev.backpack-form::formbuilder.validations.form_not_found')]); |
||
637 | } |
||
638 | |||
639 | // Update translations in bulk |
||
640 | $this->updateTranslation(FormbuilderTranslation::class, 'form_id'); |
||
641 | |||
642 | // Update form components if available |
||
643 | if (request()->has('formio_component')) { |
||
644 | $formComponents = json_decode(request()->formio_component); |
||
645 | $form->update(['formio_component' => $formComponents]); |
||
646 | |||
647 | |||
648 | $this->processFormStepsAndFields($form, $formComponents); |
||
649 | } |
||
650 | |||
651 | // \DB::commit(); |
||
652 | return $response; |
||
653 | } catch (\Exception $e) { |
||
654 | // \DB::rollBack(); |
||
655 | \Log::error('Form update failed: ' . $e->getMessage()); |
||
656 | return back()->withErrors(['message' => __('medianet-dev.backpack-form::formbuilder.validations.form_update_failed')]); |
||
657 | } |
||
658 | } |
||
659 | |||
660 | /** |
||
661 | * Save translations for a given form. |
||
662 | */ |
||
663 | protected function saveTranslations($form) |
||
664 | { |
||
665 | $translationsToInsert = []; |
||
666 | $languages = languages(); |
||
667 | foreach ($languages as $locale => $language) { |
||
668 | if (request()->has($locale)) { |
||
669 | $translationData = request()->input($locale); |
||
670 | if (isset($translationData['title']) && !empty($translationData['title'])) { |
||
671 | $translationsToInsert[] = [ |
||
672 | 'title' => $translationData['title'], |
||
673 | 'text_button' => $translationData['text_button'] ?? null, |
||
674 | 'slug' => $translationData['slug'] ?? null, |
||
675 | 'description' => $translationData['description'] ?? null, |
||
676 | 'header' => $translationData['header'] ?? null, |
||
677 | 'footer' => $translationData['footer'] ?? null, |
||
678 | 'form_id' => $form->id, |
||
679 | 'locale' => $locale, |
||
680 | 'created_at' => now(), |
||
681 | 'updated_at' => now(), |
||
682 | ]; |
||
683 | } |
||
684 | } |
||
685 | } |
||
686 | if (!empty($translationsToInsert)) { |
||
687 | FormbuilderTranslation::insert($translationsToInsert); |
||
688 | } |
||
689 | } |
||
690 | |||
691 | |||
692 | |||
693 | |||
694 | private function processFormStepsAndFields($form, $formComponents) |
||
772 | } |
||
773 | |||
774 | private function processFormStep($form, $panel, $currentLocale, $order) |
||
800 | } |
||
801 | |||
802 | private function createStepFields($form, $components, $step) |
||
803 | { |
||
804 | $fieldsMap = []; |
||
805 | |||
806 | // Create fields for this step |
||
807 | foreach ($components as $order => $component) { |
||
808 | $field = new FormField([ |
||
809 | 'form_step_id' => $step->id, |
||
810 | 'form_id' => $form->id, |
||
811 | 'key' => $component->key, |
||
812 | 'type' => $component->type, |
||
813 | 'is_active' => isset($component->isActive) ? $component->isActive : true, |
||
814 | 'is_required' => isset($component->validate) && isset($component->validate->required) ? $component->validate->required : false, |
||
815 | 'order' => isset($component->order) ? $component->order : $order, |
||
816 | ]); |
||
817 | $field->save(); |
||
818 | |||
819 | // Store field by key for condition processing |
||
820 | $fieldsMap[$component->key] = $field; |
||
821 | |||
822 | // Create field translation |
||
823 | FormFieldTranslation::create([ |
||
824 | 'label' => isset($component->label) ? $component->label : null, |
||
825 | 'placeholder' => isset($component->placeholder) ? $component->placeholder : null, |
||
826 | 'default_value' => isset($component->defaultValue) ? $component->defaultValue : null, |
||
827 | 'description' => isset($component->description) ? $component->description : null, |
||
828 | 'form_field_id' => $field->id, |
||
829 | 'locale' => App::getLocale(), |
||
830 | 'created_at' => now(), |
||
831 | 'updated_at' => now(), |
||
832 | ]); |
||
833 | } |
||
834 | |||
835 | return $fieldsMap; |
||
836 | } |
||
837 | |||
838 | private function createStandaloneFields($form, $components) |
||
839 | { |
||
840 | $fieldsMap = []; |
||
841 | |||
842 | // Create standalone fields (not associated with any step) |
||
843 | foreach ($components as $order => $component) { |
||
844 | $field = new FormField([ |
||
845 | 'form_step_id' => null, // No step association |
||
846 | 'form_id' => $form->id, |
||
847 | 'key' => $component->key, |
||
848 | 'type' => $component->type, |
||
849 | 'is_active' => isset($component->isActive) ? $component->isActive : true, |
||
850 | 'is_required' => isset($component->validate) && isset($component->validate->required) ? $component->validate->required : false, |
||
851 | 'order' => isset($component->order) ? $component->order : $order, |
||
852 | ]); |
||
853 | $field->save(); |
||
854 | |||
855 | // Store field by key for condition processing |
||
856 | $fieldsMap[$component->key] = $field; |
||
857 | |||
858 | // Create field translation |
||
859 | FormFieldTranslation::create([ |
||
860 | 'label' => isset($component->label) ? $component->label : null, |
||
861 | 'placeholder' => isset($component->placeholder) ? $component->placeholder : null, |
||
862 | 'default_value' => isset($component->defaultValue) ? $component->defaultValue : null, |
||
863 | 'description' => isset($component->description) ? $component->description : null, |
||
864 | 'form_field_id' => $field->id, |
||
865 | 'locale' => App::getLocale(), |
||
866 | 'created_at' => now(), |
||
867 | 'updated_at' => now(), |
||
868 | ]); |
||
869 | } |
||
870 | |||
871 | return $fieldsMap; |
||
872 | } |
||
873 | |||
874 | private function processComponentCondition($form, $component, $step = null) |
||
915 | } |
||
916 | } |
||
917 |
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