@@ -20,13 +20,11 @@ public function shouldIsolateOperationSetup(): bool
2020
2121 public function __construct (
2222 public string $ controller ,
23- public ?string $ route = null ,
2423 public string $ id = 'backpack-form ' ,
2524 public string $ formOperation = 'create ' ,
26- public string $ name = '' ,
27- public string $ formUrl = 'create ' ,
25+ public ?string $ formUrl = null ,
2826 public ?string $ formAction = null ,
29- public string $ formMethod = ' post ' ,
27+ public ? string $ formMethod = null ,
3028 public bool $ hasUploadFields = false ,
3129 public $ entry = null ,
3230 public ?Closure $ setup = null ,
@@ -35,16 +33,9 @@ public function __construct(
3533 public string $ classes = 'modal-dialog modal-lg ' ,
3634 public bool $ refreshDatatable = false ,
3735 ) {
38- // If route is not provided (e.g., when rendering via AJAX), get it from CRUD panel
39- if ($ this ->route === null ) {
40- \Backpack \CRUD \CrudManager::setActiveController ($ controller );
41- $ tempCrud = \Backpack \CRUD \CrudManager::setupCrudPanel ($ controller , $ this ->formOperation );
42- $ this ->route = $ tempCrud ->route ;
43- \Backpack \CRUD \CrudManager::unsetActiveController ();
44- }
45-
46- // keep backwards compatible behavior for resolving route when not provided
47- $ this ->formAction = $ this ->formAction ?? url ($ this ->route );
36+ \Backpack \CRUD \CrudManager::setActiveController ($ controller );
37+ $ this ->crud = \Backpack \CRUD \CrudManager::setupCrudPanel ($ controller , $ this ->formOperation );
38+ \Backpack \CRUD \CrudManager::unsetActiveController ();
4839 }
4940
5041 /**
@@ -61,7 +52,6 @@ protected function cacheSetupClosure(): void
6152 $ this ->hashedFormId , // Use the hashed ID that matches what Dataform component generates
6253 $ this ->controller ,
6354 $ this ->setup ,
64- $ this ->name ,
6555 $ tempCrud ,
6656 $ this ->entry
6757 );
@@ -77,9 +67,14 @@ protected function cacheSetupClosure(): void
7767 public function render ()
7868 {
7969 $ this ->hashedFormId = $ this ->id .md5 ($ this ->formAction .$ this ->formOperation .'post ' .$ this ->controller );
70+
71+ if (empty ($ this ->formUrl )) {
72+ $ this ->formUrl = isset ($ this ->entry ) ? url ($ this ->crud ->route .'/ ' .$ this ->entry ->getKey ().'/edit ' ) : url ($ this ->crud ->route .'/create ' );
73+ }
8074
81- if ($ this ->entry ) {
82- $ this ->formUrl = $ this ->formUrl ?? url ($ this ->route .'/ ' .$ this ->entry ->getKey ().'/edit ' );
75+ if (empty ($ this ->formAction )) {
76+ $ this ->formAction = isset ($ this ->entry ) ? url ($ this ->crud ->route .'/ ' .$ this ->entry ->getKey ()) : url ($ this ->crud ->route );
77+ $ this ->formMethod = $ this ->formMethod ?? (isset ($ this ->entry ) ? 'put ' : 'post ' );
8378 }
8479
8580 // Cache the setup closure if provided (for retrieval during AJAX request)
@@ -100,7 +95,6 @@ public function render()
10095 'classes ' => $ this ->classes ,
10196 'hashedFormId ' => $ this ->hashedFormId ,
10297 'controller ' => $ this ->controller ,
103- 'route ' => $ this ->route , // Pass the route for building URLs in the template
10498 ]);
10599 }
106100}
0 commit comments