1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\app\View\Components; |
4
|
|
|
|
5
|
|
|
use Backpack\CRUD\CrudManager; |
6
|
|
|
use Illuminate\View\Component; |
7
|
|
|
|
8
|
|
|
class DataForm extends Component |
9
|
|
|
{ |
10
|
|
|
public $crud; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Create a new component instance. |
14
|
|
|
* |
15
|
|
|
* @param string $controller The CRUD controller class name |
16
|
|
|
* @param string $operation The operation to use (create, update, etc.) |
17
|
|
|
* @param string|null $action Custom form action URL |
18
|
|
|
* @param string $method Form method (post, put, etc.) |
19
|
|
|
*/ |
20
|
|
|
public function __construct( |
21
|
|
|
public string $controller, |
22
|
|
|
public string $id = 'backpack-form', |
23
|
|
|
public string $operation = 'create', |
24
|
|
|
public ?string $action = null, |
25
|
|
|
public string $method = 'post', |
26
|
|
|
public bool $hasUploadFields = false, |
27
|
|
|
|
28
|
|
|
) { |
29
|
|
|
// Get CRUD panel instance from the controller |
30
|
|
|
if (CrudManager::hasCrudPanel($controller)) { |
|
|
|
|
31
|
|
|
$previousOperation = CrudManager::getCrudPanel($controller)->getOperation(); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$this->crud = CrudManager::setupCrudPanel($controller, $operation); |
|
|
|
|
35
|
|
|
|
36
|
|
|
if (isset($previousOperation)) { |
37
|
|
|
$this->crud->setOperation($previousOperation); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$this->operation = $operation; |
41
|
|
|
$this->action = $action ?? url($this->crud->route); |
|
|
|
|
42
|
|
|
$this->hasUploadFields = $this->crud->hasUploadFields($operation); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get the view / contents that represent the component. |
47
|
|
|
* |
48
|
|
|
* @return \Illuminate\Contracts\View\View|\Closure|string |
49
|
|
|
*/ |
50
|
|
|
public function render() |
51
|
|
|
{ |
52
|
|
|
return view('crud::components.form.form', [ |
53
|
|
|
'crud' => $this->crud, |
54
|
|
|
'saveAction' => $this->crud->getSaveAction(), |
55
|
|
|
'id' => $this->id, |
56
|
|
|
'operation' => $this->operation, |
57
|
|
|
'action' => $this->action, |
58
|
|
|
'method' => $this->method, |
59
|
|
|
]); |
60
|
|
|
} |
61
|
|
|
} |