diff --git a/src/CrudPanelManager.php b/src/CrudPanelManager.php index cb7af75a2f..8979e34169 100644 --- a/src/CrudPanelManager.php +++ b/src/CrudPanelManager.php @@ -69,7 +69,9 @@ public function setupCrudPanel(string $controller, ?string $operation = null): C $crud->setOperation($operation); $primaryControllerRequest = $this->cruds[array_key_first($this->cruds)]->getRequest(); - if (! $crud->isInitialized()) { + if (! $crud->isInitialized() || ! $this->isOperationInitialized($controller::class, $operation)) { + self::setActiveController($controller::class); + $crud->initialized = false; self::setActiveController($controller::class); $controller->initializeCrudPanel($primaryControllerRequest, $crud); self::unsetActiveController(); @@ -81,6 +83,14 @@ public function setupCrudPanel(string $controller, ?string $operation = null): C return $this->cruds[$controller::class]; } + /** + * Check if a specific operation has been initialized for a controller. + */ + public function isOperationInitialized(string $controller, string $operation): bool + { + return in_array($operation, $this->getInitializedOperations($controller), true); + } + /** * Record that an operation has been initialized for a controller. * diff --git a/src/app/View/Components/Dataform.php b/src/app/View/Components/Dataform.php new file mode 100644 index 0000000000..2cf98e6928 --- /dev/null +++ b/src/app/View/Components/Dataform.php @@ -0,0 +1,71 @@ +getOperation(); + } + + $this->crud = CrudManager::setupCrudPanel($controller, $operation); + + if (isset($previousOperation)) { + $this->crud->setOperation($previousOperation); + } + + if ($this->entry && $this->operation === 'update') { + $this->action = $action ?? url($this->crud->route.'/'.$this->entry->getKey()); + $this->method = 'put'; + $this->crud->entry = $this->entry; + $this->crud->setOperationSetting('fields', $this->crud->getUpdateFields()); + } else { + $this->action = $action ?? url($this->crud->route); + } + $this->hasUploadFields = $this->crud->hasUploadFields($operation, $this->entry?->getKey()); + $this->id = $id.md5($this->action.$this->operation.$this->method.$this->controller); + } + + /** + * Get the view / contents that represent the component. + * + * @return \Illuminate\Contracts\View\View|\Closure|string + */ + public function render() + { + return view('crud::components.dataform.form', [ + 'crud' => $this->crud, + 'saveAction' => $this->crud->getSaveAction(), + 'id' => $this->id, + 'operation' => $this->operation, + 'action' => $this->action, + 'method' => $this->method, + 'hasUploadFields' => $this->hasUploadFields, + 'entry' => $this->entry, + ]); + } +} diff --git a/src/resources/views/crud/components/dataform/form.blade.php b/src/resources/views/crud/components/dataform/form.blade.php new file mode 100644 index 0000000000..e72b4ab5ce --- /dev/null +++ b/src/resources/views/crud/components/dataform/form.blade.php @@ -0,0 +1,52 @@ +