Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to generate forms without id, use named parameters in formAction #204

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/Console/Commands/CrudFormOperationBackpackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CrudFormOperationBackpackCommand extends GeneratorCommand
*
* @var string
*/
protected $signature = 'backpack:crud-form-operation {name}';
protected $signature = 'backpack:crud-form-operation {name} {--no-id}';

/**
* The console command description.
Expand Down Expand Up @@ -71,12 +71,8 @@ protected function getDefaultNamespace($rootNamespace)

/**
* Replace the table name for the given stub.
*
* @param string $stub
* @param string $name
* @return string
*/
protected function replaceNameStrings(&$stub, $name)
protected function replaceNameStrings(string &$stub, string $name): self
{
$name = Str::of($name)->afterLast('\\');

Expand All @@ -85,6 +81,11 @@ protected function replaceNameStrings(&$stub, $name)
$stub = str_replace('Dummy Class', $name->snake()->replace('_', ' ')->title(), $stub);
$stub = str_replace('dummy-class', $name->snake('-'), $stub);
$stub = str_replace('dummy_class', $name->snake(), $stub);
$stub = str_replace('DUMMY_ROUTE_WITH_ID', $this->option('no-id') ? 'false' : 'true', $stub);
$stub = str_replace('DUMMY_BUTTON_STACK', $this->option('no-id') ? 'top' : 'line', $stub);
$stub = str_replace('DUMMY_FORM_ACTION_CALLBACK', $this->option('no-id') ? 'formLogic: function ($inputs, $entry) {' : 'id: $id, formLogic: function ($inputs, $entry) {', $stub);
$stub = str_replace('DUMMY_FUNCTION_PARAMETERS', $this->option('no-id') ? '' : 'int $id', $stub);
$stub = str_replace('DUMMY_GETFORM_VIEW_PARAMETER', $this->option('no-id') ? '' : '$id', $stub);

return $this;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Console/stubs/crud-form-operation.stub
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ trait DummyClassOperation
{
$this->formRoutes(
operationName: 'dummyClass',
routesHaveIdSegment: true,
routesHaveIdSegment: DUMMY_ROUTE_WITH_ID,
segment: $segment,
routeName: $routeName,
controller: $controller
Expand All @@ -33,7 +33,7 @@ trait DummyClassOperation
{
$this->formDefaults(
operationName: 'dummyClass',
// buttonStack: 'line', // alternatives: top, bottom
buttonStack: 'DUMMY_BUTTON_STACK', // alternatives: top, bottom
// buttonMeta: [
// 'icon' => 'la la-home',
// 'label' => 'Dummy Class',
Expand All @@ -48,23 +48,23 @@ trait DummyClassOperation
* Method to handle the GET request and display the View with a Backpack form
*
*/
public function getDummyClassForm(?int $id = null) : \Illuminate\Contracts\View\View
public function getDummyClassForm(DUMMY_FUNCTION_PARAMETERS) : \Illuminate\Contracts\View\View
{
$this->crud->hasAccessOrFail('dummyClass');

return $this->formView($id);
return $this->formView(DUMMY_GETFORM_VIEW_PARAMETER);
}

/**
* Method to handle the POST request and perform the operation
*
* @return array|\Illuminate\Http\RedirectResponse
*/
public function postDummyClassForm(?int $id = null)
public function postDummyClassForm(DUMMY_FUNCTION_PARAMETERS)
{
$this->crud->hasAccessOrFail('dummyClass');

return $this->formAction($id, function ($inputs, $entry) {
return $this->formAction(DUMMY_FORM_ACTION_CALLBACK
// You logic goes here...
// dd('got to ' . __METHOD__, $inputs, $entry);

Expand Down